I gave up on on my previous issue, (http://forums.libsdl.org/viewtopic.php?t=9975&highlight=) and now I’m just trying to fill some rects. SDL_FillRect() and SDL_FillRects() are failing in the strangest way.
I’m using SDL2-2.0.1 on Window 7, MSVC 2008. Return codes from all functions are tested, but error checking removed below for clarity.
Here’s the surface I’m trying to fill:
Code:
const SDL_Color gridCols[] = {
{ 0xFF, 0xFF, 0xFF, 0xFF }, // white
{ 0x00, 0x00, 0x00, 0xFF } // transparency
};
m_pGridSurf = SDL_CreateRGBSurface(0, 364, 304, 8, 0, 0, 0, 0);
SDL_SetSurfaceBlendMode(m_pGridSurf, SDL_BLENDMODE_NONE);
SDL_SetPaletteColors(m_pGridSurf->format->palette, gridCols, 0, 2);
SDL_SetColorKey(m_pGridSurf, SDL_TRUE, 1);
This works exactly as you might expect, filling in the rectangle with white:
Code:
SDL_Rect test = { 10, 10, 100, 100 };
SDL_FillRect(m_pGridSurf, &test, 0);
Whereas this causes an access violation at the SDL_FillRect():
Code:
SDL_Rect test = { 10, 10, 50, 100 };
SDL_FillRect(m_pGridSurf, &test, 0);
Unhandled exception at 0x6c7a2a15 (SDL2.dll) in O2.exe: 0xC0000005: Access violation reading location 0x00000000.
The only difference is the width of the rectangle. I am completely baffled. I can’t simplify this code any more. Any suggestions on tracking down the issue, or what I’m doing wrong?