Jump to content
  • Advertisement
Sign in to follow this  
d h k

[ SDL ] SetColorKey causes Error

This topic is 4727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody and sorry that I have just another problem today... After adding the loading tiles from mapfiles functionality, I added collision checking ( which I got to work ) and then I added the possibility to declare a tile "transparent"... I added a new bool transparent parameter to my struct tile and initialize it with true or false according to the sprite. Then when I draw it I use the following code:
for ( int x = 0; x < TILES_X; x++ )
{
	for ( int y = 0; y < TILES_Y; y++ )
	{
		if ( tile[x][y].transparent == true )
			SDL_SetColorKey ( globals.tile[x][y], SDL_SRCCOLORKEY, SDL_MapRGB ( globals.tile[x][y]->format, 0, 0, 0 ) );
		else
			SDL_SetColorKey ( globals.tile[x][y], 0, SDL_MapRGB ( globals.tile[x][y]->format, 0, 0, 0 ) );

			DrawIMG ( globals.tile[x][y], TILE_WIDTH * x, TILE_HEIGHT * y );
	}
}

What I am doing ( or trying to do ) is to go through all my tiles, check if they should be drawn transparent, set the transparent color accordingly and then draw the sucker. That should be really easy, but it isn't. Now to the stuff that does not work: Whenever I even call the "SDL_SetColorKey" function, the "Fatal signal: Segmentation Fault (SDL Parachute Deployed)" error comes up and the game shuts down... Even if I initialize all my sprites with "transparent = false". I know that my tiles are working and that the transparency of my animated sprites are working just fine as well... Can anyone tell if there's something wrong in that script? Is there any little "catch" to SDL_SetColorKey that I don't know yet?

Share this post


Link to post
Share on other sites
Advertisement
A "Fatal signal: Segmentation Fault (SDL Parachute Deployed)" usually means something wrong with memory access. So first thing you must check to make sure that tile is defined as tile[TILES_X][TILES_Y]; as in it has TILES_X rows and TILES_Y cols. Next, if the sprite does not have a transparent color, you do not need to call a function that sets the transparent color. Remove the:

else
SDL_SetColorKey ( globals.tile[x][y], 0, SDL_MapRGB ( globals.tile[x][y]->format, 0, 0, 0 ) );

code because it is not needed. That will probabally cause an error because of the flags you are passing in. Here's the reference for SDL_SetColorKey. Good luck!

Share this post


Link to post
Share on other sites
Wow, Drew you've been helping me out a lot already, thanks for that.

My tiles are defined correctly, but removing the else statement made it work fine. I thought you need to run it in order to disable transparency, but I didn't think that I would access a new tile in every run anyways...

Thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!