[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] no unlock: surfarray.pixels2d() and PixelArray() bug or intented?



from the docs:
"During its lifetime, the PixelArray locks the surface, thus you explicitly have to delete it once its not used anymore and the surface should perform operations in the same scope."

so the idea is to do something more like this:
   self.pixels = pygame.PixelArray( self.screen )  # locks screen
   draw()
   del self.pixels  # automatically unlocks screen
   self.screen.blit ( image, dest_rect )

or maybe more like this:
   # as long as nobody stores a reference to the pixelarray, this ties the screen locking to the draw call
   draw(pygame.PixelArray( self.screen )) 
   self.screen.blit ( image, dest_rect )

or possibly to use the pixel array in a more fine grained way within the draw call

If there were ways to make it more clear that this is the behavior, or something to do to help you write the code you want, than PixelArray can be changed as needed


On Sat, Jun 7, 2008 at 9:12 AM, Jake b <ninmonkeys@xxxxxxxxx> wrote:
I was able to get it working by manually unlocking. It just seemed weird design:

# (1) before needing pixels
init()
   # ...
draw()
   self.screen.blit ( image, dest_rect )

# (2) adding pixel refs; breaks blit down the line
init()
   self.pixels = pygame.PixelArray( self.screen )
draw()
   self.screen.blit ( image, dest_rect )

# (3) which does an exception, but you can fix it:
init()
   self.pixels = pygame.PixelArray( self.screen )
   self.screen.unlock()
draw()
   self.screen.blit ( image, dest_rect )

--
Jake