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

Re: [pygame] BUG: Segfault when rotating a HWSURFACE



Thanks John, and John.

Committed revision 1004.

On 5/15/07, John Popplewell <john@xxxxxxxxxxxxxxxxxxxxxx> wrote:
On Mon, May 14, 2007 at 02:52:38PM -0600, John Krukoff wrote:
> import sys, pygame
>
> pygame.init( )
> screen = pygame.display.set_mode( ( 640, 480 ), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN )
> hwSurface = pygame.surface.Surface( ( 64, 64 ), pygame.HWSURFACE )
> hwSurface.fill( ( 0, 0, 0 ) )
> print 'Should show 1 to indicate hardware surface:', hwSurface.get_flags( )
> # Crash occurs on next line.
> rotated = pygame.transform.rotate( hwSurface, 1 )
> print 'Will never be displayed.'
> sys.exit( 0 )

I can reproduce this with the latest svn although I have to set an environment
variable to get the directx backend (with actual hardware surfaces). Here is a
patch to fix it:

Index: src/transform.c
===================================================================
--- src/transform.c     (revision 1003)
+++ src/transform.c     (working copy)
@@ -528,6 +528,7 @@
        }
        else
        {
+               SDL_LockSurface(surf);
                switch(surf->format->BytesPerPixel)
                {
                case 1: bgcolor = *(Uint8*)surf->pixels; break;
@@ -540,6 +541,7 @@
                        bgcolor = (((Uint8*)surf->pixels)[2]) + (((Uint8*)surf->pixels)[1]<<8) + (((Uint8*)surf->pixels)[0]<<16);
 #endif
                }
+               SDL_UnlockSurface(surf);
                bgcolor &= ~surf->format->Amask;
        }


Whilst I was doing this I found a small regression building movie.c on Windows with the Microsoft compiler. Here is a patch to fix it:

Index: src/movie.c
===================================================================
--- src/movie.c (revision 1003)
+++ src/movie.c (working copy)
@@ -148,8 +148,8 @@

                if(posobj == NULL)
                {
+                       SMPEG_Info info;
                         Py_BEGIN_ALLOW_THREADS
-                       SMPEG_Info info;
                        SMPEG_getinfo(movie, &info);
                        SMPEG_scaleXY(movie, info.width, info.height);
                         Py_END_ALLOW_THREADS
@@ -157,8 +157,8 @@
                }
                else if(TwoIntsFromObj(posobj, &x, &y))
                {
+                       SMPEG_Info info;
                         Py_BEGIN_ALLOW_THREADS
-                       SMPEG_Info info;
                        SMPEG_getinfo(movie, &info);
                        SMPEG_scaleXY(movie, info.width, info.height);
                         Py_END_ALLOW_THREADS

Hope this helps,

regards,
John.