Hello i want to make a menu for a video games i code with xcode and i received this error:
exc BAD ACCESS i think it 's a memory error do you have an idea how can i fix this ?
It’s my code for the menu on a different file :
LTexture gBoutonsTexture;
////Scene texture
LTexture gMenuTexture;
bool loadMenu (SDL_Rect* gBoutonsClips[ 4 ]){
//Loading success flag
bool success = true;if( !gMenuTexture.loadFromFile( "/Users/Myriam/Downloads/projet du labyrinthe2017/menu/fond.bmp" ) ) { printf( "Failed to load menu!\n" ); success = false; }//image de fond //Load sprite sheet texture if( !gBoutonsTexture.loadFromFile( "/Users/Myriam/Downloads/projet du labyrinthe2017/SPRITES /boutons copie.png" ) ) { printf( "Failed to load sprite sheet texture!\n" ); success = false; } else{ //boutons du menu // Set sprites for( int i = 0; i < TOTAL_BUTTONS; ++i ) { gBoutonsClips[ i ]->x = 0; gBoutonsClips[ i ]->y = BUTTON_HEIGHT*i; gBoutonsClips[ i ]->w = BUTTON_WIDTH; gBoutonsClips[ i ]->h = BUTTON_HEIGHT; } } return success;
}
void affichage_menu(SDL_Rect* gBoutonsClips[ 4 ]){
gMenuTexture.render( 0, 0 ); //AFFICHAGE DU MENU EN BACKRGOUND
//Chaque bouton gBoutonsTexture.render( 40, SCREEN_HEIGHT/3, gBoutonsClips[ 0 ] );//Position play gBoutonsTexture.render( 40, SCREEN_HEIGHT/2, gBoutonsClips[ 1 ] );//Position difficulty gBoutonsTexture.render( 40, 2*SCREEN_HEIGHT/3, gBoutonsClips[ 2 ] );//Position scores gBoutonsTexture.render( 40, 5*SCREEN_HEIGHT/6, gBoutonsClips[ 3 ] );//Position rules
}
void closeMenu(SDL_Rect gBoutonsClips[ 4 ]){
gMenuTexture.free();
gBoutonsTexture.free();
}
And i have this in my main:
int main( int argc, char* args[] )
{
//Start up SDL and create window
if( !init() )
{
printf( “Failed to initialize!\n” );
}
else
{//The level tiles Tile* tileSet[ TOTAL_TILES ]; SDL_Rect* gBoutonsClips[ 4 ];
// loadMenu();
if( !loadMenu(gBoutonsClips) )
{
printf( “Failed to load menu!\n” );
}if( !chargement_perso() ) { printf( "Failed to load perso!\n" ); }
// Load media
if( !loadMedia( tileSet ) )
{
printf( “Failed to load media!\n” );
}
// chargement_perso();bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { affichage_menu(gBoutonsClips); //Play the music Mix_PlayMusic( gMusic, -1 ); //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } if( e.type == SDL_KEYDOWN && e.key.repeat == 0 ) { //Adjust the velocity switch( e.key.keysym.sym ) { case SDLK_SPACE: jouer(tileSet); break;
} }
}
// //Clear screen
// SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
// SDL_RenderClear( gRenderer );
//Update screen SDL_RenderPresent( gRenderer ); } } //Free resources and close SDL closeSdl(); return 0;
}