Skip to content

Renderer.blit() doesn't check if the texture is created by another renderer. #2622

Open
@yunline

Description

@yunline
import pygame
from pygame._sdl2.video import Window, Renderer, Texture

pygame.init()

img = pygame.Surface((128,128))
img.fill("red")

win1 = Window("win1")
win2 = Window("win2")

ren1 = Renderer(win1)
ren2 = Renderer(win2)

tex2 = Texture.from_surface(ren2, img)

ren1.blit(tex2, (0,0))

ren1.present()
ren2.present()

while 1:
    pygame.event.get()

In this example, user trys to blit tex2 (created by ren2) to ren1. Then the tex2 is draw to the ren2, without any warning or error raised.
图片

What's more? If an object that has a draw method is passed to Renderer.blit, then the draw method will be called without any checking, even though the draw function never draws on the Renderer.

So I suggest:

  • Renderer.blit() should only accept Texture, Image (and Surface?) and their subclasses.
  • Renderer.blit() should check if the Texture is created by itself.

Metadata

Metadata

Assignees

Labels

videopygame.video

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions