Fix core dump & clearer music deallocation

This commit is contained in:
Pòsweg Blumenthal 2019-12-02 11:48:01 +01:00
parent c15e4e48a5
commit f657c49c79
2 changed files with 45 additions and 57 deletions

View File

@ -1,11 +1,8 @@
#include "maps.h" #include "maps.h"
Maps::Maps(SDL_Renderer* render){ Maps::Maps(SDL_Renderer* render){
int sound = false; if(false) Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 );
if(sound == true){
Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 );
}
//Set renderer //Set renderer
renderer = render; renderer = render;
@ -31,8 +28,9 @@ Maps::~Maps(){
//Deallocate rows //Deallocate rows
for(int i = 0; i < blockTotal; ++i) delete blockRect[i]; for(int i = 0; i < blockTotal; ++i) delete blockRect[i];
//Deallocate //Deallocate
delete blockRect; //delete blockRect;
Mix_HaltMusic();
//Free the music //Free the music
Mix_FreeMusic( gMusic ); Mix_FreeMusic( gMusic );
@ -107,7 +105,6 @@ int Maps::map(std::string mapName){
} }
} }
if(currentKeyStates[SDL_SCANCODE_ESCAPE]){ if(currentKeyStates[SDL_SCANCODE_ESCAPE]){
musicQuit();
return 0; return 0;
} }
@ -141,13 +138,5 @@ int Maps::map(std::string mapName){
//Render //Render
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
musicQuit();
return -1; return -1;
} }
void Maps::musicQuit(){
Mix_HaltMusic();
//Free the music
Mix_FreeMusic( gMusic );
gMusic = NULL;
}

View File

@ -20,7 +20,6 @@ class Maps{
int map(std::string mapName); int map(std::string mapName);
private: private:
void loadMap(std::string path); void loadMap(std::string path);
void musicQuit();
SDL_Renderer* renderer; SDL_Renderer* renderer;