SDL_FillRect() causing access error only with certain input

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?

Fascinating. These pass:

Code:

SDL_Rect test = { 10, 10, 64, 100 };
SDL_Rect test = { 9, 10, 64, 100 };
SDL_Rect test = { 0, 10, 63, 100 };
SDL_Rect test = { 0, 10, 53, 100 };
SDL_Rect test = { 0, 10, 1000, 100 };

These throw an access violation:

Code:

SDL_Rect test = { 10, 10, 63, 100 };
SDL_Rect test = { 9, 10, 63, 100 };

Are there SDL binaries for Windows with debug symbols? I can’t install DirectX here to build from source, so the development libraries are the best I can do. I stripped the program down completely. This is all that’s left, and it still crashes at SDL_FillRect():

Code:

#include <SDL.h>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *pSurf = SDL_CreateRGBSurface(0, 364, 304, 8, 0, 0, 0, 0);
SDL_Rect test = { 10, 10, 50, 100 };
SDL_FillRect(pSurf, &test, 0);
SDL_Quit();
return 0;
}

It’s also only palletized surfaces. If I create a 32-bit surface, it works fine.

It’s also only palletized surfaces. If I create a 32-bit surface, it works
fine.

I tested your source on linux with an SDL slightly newer than 2.0.1 (hg of
a pair of months ago) and it works…

I remember a bug related to 8 bit surfaces during the SDL 2.x development
cycle, but I don’t use them at all so I cannot tell you if the bug is still
present.–
Bye,
Gabry

Thanks Gabry. I did manage to track it down to the call to SDL_memset() inside SDL_FillRect1SSE(). The parameters are all totally valid. Since I can’t debug into the DLL here, I copied the functions locally. If I change the call to SDL_memset(), or copy SDL_memset() locally into my main.cpp, the problem goes away.

I thought maybe it was something in the way the SDL_memset() symbol was being imported, but I can use it by doing:

Code:

Uint8 test[50];
SDL_memset(test, 50, 0);

and that doesn’t crash. Right now I’m baffled. When I get home I’m going to try to build a debug version of the library from source and see what happens.

Sorry, I meant “If I change the call to memset(), or copy SDL_memset() locally”

I just tried it on a different Windows 7 machine, and it crashes in the same way. I rebuilt SDL2.lib from source, and the crash went away.

So I still don’t know why it’s crashing, but rebuilding from source has fixed the problem.

I just tried it on a different Windows 7 machine, and it crashes in the

same way. I rebuilt SDL2.lib from source, and the crash went away.

So I still don’t know why it’s crashing, but rebuilding from source has
fixed the problem.

Maybe some ASM SSE optimizations that your recompilation removed?–
Bye,
Gabry