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

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



On, Sat Jun 07, 2008, Brian Fisher wrote:

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

No need to delete the whole pixels attribute. A self.pixels = None
should be sufficient.

> 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

A possible way would be to lock the Surface at the moment, the
PixelArray tries to access the pixel buffer. This however would slow the
whole PixelArray down and make it somewhat unusable for fast operations.

Regards
Marcus

Attachment: pgpf0UK0rgv0Q.pgp
Description: PGP signature