BUG in src/video/windx5/SDL_dx5events.c

I tracked down a bug that crashed my program on Windows all the
time.

FILE: src/video/windx5/SDL_dx5events.c

FUNCTION: handle_mouse
BUG:
    SDL_PublicSurface is being dereferenced when it is NULL.
           I added the following to the very begining of handle_mouse
    and it solved my crashing problems:

    if (SDL_PublicSurface == NULL) return;

~ Philip D.S. Thoren

I tracked down a bug that crashed my program on Windows all the
time.

Are you pumping the event queue without creating a Window? (i.e. - you’re
just using the audio subsystem and never called SDL_SetVideoMode() or
something wacky like that)?

I put your fix into CVS…it’s a good sanity check if nothing else.

Thanks,
–ryan.

Sorry, I forgot to explain what was happening to cause this.

I’m working with several threads. Of those threads one will pump the events(1) and one handles displaying(2).

When resizing the screen, there is a point at which the SDL_PublicSurface becomes NULL as a result of thread
(2)'s operations. Thread (1) ends up calling the handle_mouse function ( which tries to dereference the
SDL_PublicSurface ) while (2) is still in limbo.

About the fix I suggested:
Perhaps returning right away isn’t the more correct answer. The only thing that uses the SDL_PublicSurface is
the check at the beginning. I just tested to see if this will work and it has the same results as just
returning from the function:

 /* This check prevents segfaulting for threaded processes
    that handle displaying and events in separate threads */
 if (SDL_PublicSurface != NULL)
 {
 	/* If we are in windowed mode, Windows is taking care of the mouse */
    if (  (SDL_PublicSurface->flags & SDL_OPENGL) ||
         !(SDL_PublicSurface->flags & SDL_FULLSCREEN) ) {
 		return;
    }
 }

How thread safe is SDL? As I was tracking down this small problem I did notice other places that would
dereference pointers without the sanity check for NULL.

~ Phil Thoren

Ryan C. Gordon wrote:>> I tracked down a bug that crashed my program on Windows all the

time.

Are you pumping the event queue without creating a Window? (i.e. - you’re
just using the audio subsystem and never called SDL_SetVideoMode() or
something wacky like that)?

I put your fix into CVS…it’s a good sanity check if nothing else.

Thanks,
–ryan.