Skip to main content
gamedev.net
🔒 Locked

SDL_FillRect

Started by LostSnow25 1 reply 3.4k views
Original Post
LostSnow25
LostSnow25
What is the syntax for this function? The code below compiles but when I create a button I get an access violation on color = SDL_MapRGB(palette, 52 ,52 ,52);


Uint32 color;
SDL_PixelFormat *palette;
color = SDL_MapRGB(palette, 52, 52, 52);
SDL_FillRect(surface, &menu, color);


BlodBath
BlodBath
Palette needs to be a SDL_PixelFormat structure. You're passing in an uninitialized pointer; use the format field of your desired buffer object (typically the screen buffer).
Servant of the Lord
Servant of the Lord
As blodbath said, your 'palette' is a pointer that you aren't pointing at anything. You are supposed to pass in the PixelFormat of the surface you are wanting to map the color to, because the PixelFormats can from surface to surface in some cases.

They are wanting you to do this:

Uint32 color;color = SDL_MapRGB(surface->format, 52, 52, 52);SDL_FillRect(surface, &menu, color);


If you don't set your pointers to anything, they point to (seemingly) random chunks of ram, and can affect your program in really weird ways. Sometimes, the code even seems like it's working fine, until sometime in the future when it suddenly starts crashing for (seemingly) no reason.

Always make sure your pointers are pointing to something when you create them. (At the very least, initialize them to NULL)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.