In pygame blit of subsurface cause error that the subsurface is locked

徘徊边缘 提交于 2020-01-02 05:21:10

问题


Here is a minimal script to reproduce that

#!/usr/bin/env python
import pygame

screen = pygame.display.set_mode((640, 480))
screen.fill((255, 255, 255))
screen_half = screen.subsurface((0,0, 640/2.0, 480))

print screen.get_locks()
print screen_half.get_locks()
screen_half.blit(screen_half, (0, 0))

the output is

()
()
Traceback (most recent call last):
  File "./blit_test.py", line 10, in <module>
    screen_half.blit(screen_half, (0, 0))
pygame.error: Surfaces must not be locked during blit

As you can see tuples with locks for screen and screen_half are empty. There is no error if I use screen instead of screen_half.


回答1:


I had similar problem and pmoreli is right. I just copied subsurface creating new surface and than blit it on display:

screen_half = screen_half.copy()
screen_half.blit(screen_half, (0, 0))



回答2:


Probably the lock occurs during the blit. You're blitting a surface into itself, that's why you get the error.

If you want to copy half of the screen into the other half, you can ".copy" the subsurface and then blit it.



来源:https://stackoverflow.com/questions/4117407/in-pygame-blit-of-subsurface-cause-error-that-the-subsurface-is-locked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!