Detecting lost surfaces with SDL's DirectDraw driver

I’ve been running into some problems using SDL and it’s DirectDraw driver.
Any assistance would be greatly appreciated…

I have an SDL application that needs to deal with video mode changes made
from Windows’ Display control panel. When the resolution is changed, blits
will work fine (and not report lost surfaces), however the call to SDL_Flip
does not. The application will continue to run except that the screen,
which was created with SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE), will
not get redrawn. A few runs through the debugger indicated that SDL has a
buffer that gets blitted to the actual screen (in
sdl_dx5video.c:DX5_WindowUpdate). DirectX will indicate that the blit
failed and that it was due to a lost surface. SDL’s response is to restore
the surface (through DirectDraw) and try again. The 2nd blit will also
fail, however SDL does not report this error to the application.

What I’d like to be able to do is catch the failed call to SDL_UpdateRect
and then do my own restore. Unfortunately, there does not seem to be a way
to do this, other than modifying the SDL source (which I’d be happy to do,
but would rather avoid if possible) or poking around in data structures
internal to SDL. Is there a better way to do this? Catching
WM_DISPLAYCHANGE messages seems like one possibility, however handling a
DirectDraw error seems like the better way to go.–
David Ludwig
davidl at