SDL_SetColorKey crashes and wont work in SDL2

Hey guys I’m trying to work on bitmap transparency but it crashes and just…doesn’t work.
I’ve got my render draw code in a function its all there, but why does the program keep crashing.

int main( int argc , char *argv[] )
{
SDL_Window *window = NULL ;
SDL_Renderer *renderer = NULL ;
SDL_Surface *ship_Surf = NULL ;

if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) != 0 )
{
SDL_Log( “Could not initialize SDL2: returned %s”, SDL_GetError() ) ;
return 1 ;
}

window = SDL_CreateWindow( “Space Invaders : Example” ,
posX , posY , width , height, 0 ) ;
renderer = SDL_CreateRenderer( window , -1 , SDL_RENDERER_ACCELERATED ) ;

ship_Surf = SDL_LoadBMP( “ship.bmp” ) ;
loading_Tex = SDL_CreateTextureFromSurface( renderer , ship_Surf ) ;
SDL_FreeSurface( ship_Surf ) ;

SDL_SetColorKey( ship_Surf , SDL_TRUE , SDL_MapRGB( ship_Surf->format , 0 , 0 , 255 ) ) ;

/* Game Loops here /
/
blah blah blah */

SDL_DestroyRenderer( renderer ) ;
SDL_DestroyWindow( window ) ;
SDL_Quit() ;

return 0 ;
}

SDL_FreeSurface( ship_Surf ) ;
SDL_SetColorKey( ship_Surf , SDL_TRUE , SDL_MapRGB( ship_Surf->format , 0 , 0 , 255 ) ) ;

of course it crashes if you first free the surface and then try to use
it in a function.

Ok, it doesn’t crash any more but it still doesn’t change the transparency background of the sprite.

SDL_CreateTextureFromSurface() basically copies the surface into a texture - so modifying the surface afterwards (e.g. with SDL_SetColorKey()) can’t change the texture :wink:

Ah, the bitmap still has that blue background its really annoying.