Hi,
I’m the lead developer of a game - Battle for Wesnoth (http://www.wesnoth.org) that uses SDL. While we’ve mostly found SDL easy to use and reliable, we’ve recently come across a problem, and we’re trying to work out if it’s due to our own misunderstanding of the SDL API, or a bug in SDL.
It seems that calling the function SDL_DisplayFormatAlpha() on a surface will sometimes cause the source surface to be corrupted, particularly after the surface returned from SDL_DisplayFormatAlpha() is freed.
We have managed to boil this down to a minimal case. There is a source file at http://www.whitevine.net/sdlproblem/main.c and a data file at http://www.whitevine.net/sdlproblem/img.bmp – to reproduce the problem, compile main.c, linking to SDL, and then run the program with img.bmp in the directory you’re running the program from.
The expected result of the program is to display img.bmp twice on the screen. The result we’ve been getting is the first time img.bmp displays correctly, and the second time it is ‘corrupted’ (it resembles yellow static).
Why the image is being corrupted, I’m not sure. However, removing the call to SDL_DisplayFormatAlpha that assigns the result to ‘dummy_tmp’ causes the program to run as expected. Even removing the call SDL_FreeSurface(dummy_tmp) causes the program to run as expected.
I am working under the assumption that SDL_DisplayFormatAlpha() can be called on any valid surface, and that it returns a completely new surface, and doesn’t mutate its argument. Is this assumption correct? It seems in the given test program, it sometimes does mutate its argument.
I, and users of my program, have tested this under Windows XP using SDL 1.2.6, and under SDL 1.2.5, 1.2.6, and SDL CVS using GNU/Linux. All these platforms had the problem. We’ve also tested under SDL 1.2.5 using FreeBSD, and it didn’t have the problem.
Any help would be greatly appreciated.
David White
Lead Developer, Battle for Wesnoth (http://www.wesnoth.org)