Crash When Calling SDL_DisplayFormat At Some Window Sizes

I am having an odd problem with a light development tool I made for the
artist working on my current project. The viewer can open in one of
two modes, one of which displays in a 126 pixel wide, 256 pixel tall
window, the second of which displays in a 640 pixel wide, 480 pixel
tall window (appropriate values are retrieved from a parsed .txt and
placed into variables). In both cases, the screen is retrieved via a
call to SDL_SetVideoMode() with appropriate values passed in. A 640 x
480 bitmap is loaded and used as the backdrop for the art asset being
examined. The bitmap loading code looks like this:----

SDL_Surface bitmap_p = NULL;
SDL_Surface *tempBitmap_p = SDL_LoadBMP(filename.c_str());
SDL_SetColorKey(tempBitmap_p, SDL_SRCCOLORKEY, transparencyColor);
bitmap_p = SDL_DisplayFormat(tempBitmap_p);
SDL_FreeSurface(tempBitmap_p);


If the viewer is loaded (and SDL_SetVideoMode called) in the 128 x 256
mode, this code works fine and a subsection of the 640 x 480 surface
is used as the backdrop without problems. If the viewer is loaded in
the 640 x 480 mode, the call to SDL_DisplayFormat crashes the
application. Stepping into the call to SDL_DisplayFormat in the
debugger immediately terminates the debugger session with an access
violation.

I played with the window sizes and found that there was a maximum
window size, above which calls to SDL_DisplayFormat crashed and
below which calls to SDL_DisplayFormat succeeded. The critcal values
appeared to be in the 640 x 202 range. Here is a range of test
results I did by hand.


640 x 203 = 129,920 BAD
640 x 202 = 129,280 GOOD
202 x 640 = 129,280 GOOD
203 x 640 = 129,920 BAD
360 x 360 = 129,600 GOOD
361 x 361 = 130,321 BAD
360 x 361 = 129,960 BAD


My reaction to this as the developer is precisely, ‘Huh?’. Does
anybody have any insight to offer? I am very confused that
changing the requested size of the screen display would affect the
behavior of SDL_DisplayFormat. SDL_DisplayFormat, though it does
reference the screen display, should only need the format of the
screen and should not fail based on the size of the screen. Or so
it seems to me.

                                                Nathaniel Barnes
                                                      Programmer
                                                    D.O.G. Games

Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25?

NBarnes wrote:

[snip]

My reaction to this as the developer is precisely, ‘Huh?’. Does
anybody have any insight to offer? I am very confused that
changing the requested size of the screen display would affect the
behavior of SDL_DisplayFormat. SDL_DisplayFormat, though it does
reference the screen display, should only need the format of the
screen and should not fail based on the size of the screen. Or so
it seems to me.

Did you try a memory checker ? Try electric fence or valgrind for
example, I bet these could reveal some “interesting” things :wink:

Stephane