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

Re: [pygame] Segmentation Fault



Thanks.

That has been added to cvs.

I wonder if there was a reason for the extra surf =
PySurface_AsSurface(surface); line?



On 10/28/05, John Popplewell <john@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> [I sent this mail early this morning but it seems to have gone missing]
> Hi,
>
> I was working on a game and used:
>
> export set SDL_VIDEODRIVER=bobble
>
> to see what would happen with an invalid driver name.
> Bang! Turned out that the GP was triggered by this sequence:
>
> C:>python
> Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pygame
> >>> pygame.init()
> (5, 1)
> >>> icon = pygame.image.load("icon32x32.png")
> >>> pygame.display.set_icon(icon)
> Fatal Python error: (pygame parachute) Segmentation Fault
>
> abnormal program termination
> C:>
>
> I tracked it down to the fact that SDL_WM_SetIcon() was being called even
> though SDL_Init(SDL_INIT_VIDEO) had failed.
>
> Happens on Linux as well as Windows. Not particularly important, but it wasted
> a chunk of my time.
>
> Here's a diff against current CVS that also removes some redundancy,
>
> cheers,
> John Popplewell.
>
> Index: display.c
> ===================================================================
> RCS file: /home/cvspsrv/cvsroot/games/pygame/src/display.c,v
> retrieving revision 1.64
> diff -c -r1.64 display.c
> *** display.c   3 Oct 2005 06:52:07 -0000       1.64
> --- display.c   27 Oct 2005 02:08:59 -0000
> ***************
> *** 919,925 ****
>   static void do_set_icon(PyObject *surface)
>   {
>         SDL_Surface* surf = PySurface_AsSurface(surface);
> !       surf = PySurface_AsSurface(surface);
>         SDL_WM_SetIcon(surf, NULL);
>         icon_was_set = 1;
>   }
> --- 919,925 ----
>   static void do_set_icon(PyObject *surface)
>   {
>         SDL_Surface* surf = PySurface_AsSurface(surface);
> !
>         SDL_WM_SetIcon(surf, NULL);
>         icon_was_set = 1;
>   }
> ***************
> *** 930,935 ****
> --- 930,937 ----
>         PyObject* surface;
>         if(!PyArg_ParseTuple(arg, "O!", &PySurface_Type, &surface))
>                 return NULL;
> +       if(!PyGame_Video_AutoInit())
> +               return RAISE(PyExc_SDLError, SDL_GetError());
>         do_set_icon(surface);
>         RETURN_NONE
>   }
>
>
>