In pygame blit subsurface causes an error that the subsurface is locked

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)) 

output

 () () 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, the lock tuples for the screen and screen_half are empty. There is no error if I use screen instead of screen_half .

+4
source share
2 answers

The lock probably happens during blit. You mix the surface in yourself, so you get an error.

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

+1
source

I had a similar problem and pmoreli is right. I just copied the subsurface layer, creating a new surface, not a blister on the display:

 screen_half = screen_half.copy() screen_half.blit(screen_half, (0, 0)) 
+1
source

All Articles