Skip to content

Commit

Permalink
Added failsafe for overflow of textures, music and sfx
Browse files Browse the repository at this point in the history
  • Loading branch information
t3m1X committed Mar 30, 2017
1 parent 86b5319 commit 7382499
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ModuleAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Mix_Chunk * const ModuleAudio::LoadSFX(const char * path)
{
Mix_Chunk* ret = nullptr;

if (last_sfx == MAX_MUSIC) {
LOG("Overflow error: Overwriting sfx");
last_sfx = 0;
}

sfx[last_sfx] = Mix_LoadWAV(path);

if (sfx[last_sfx] == NULL) {
Expand All @@ -73,6 +78,11 @@ Mix_Music * const ModuleAudio::LoadMusic(const char * path)
{
Mix_Music* ret = nullptr;

if (last_music == MAX_MUSIC) {
LOG("Overflow error: Overwriting music");
last_music = 0;
}

musics[last_music] = Mix_LoadMUS(path);

if (!musics[last_music]) {
Expand Down
4 changes: 4 additions & 0 deletions ModuleTextures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ SDL_Texture* const ModuleTextures::Load(const char* path)
LOG("Failed to load image IMG_Load: %s\n", IMG_GetError());
}
else {
if (last_texture == MAX_TEXTURES) {
LOG("Overflow error: Overwriting textures. \n");
last_texture = 0;
}
textures[last_texture] = SDL_CreateTextureFromSurface(App->render->renderer, image);
if (textures[last_texture] == NULL) {
LOG("Failed to create texture from surface SDL_CreateTextureFromSurface: %s\n", SDL_GetError());
Expand Down

0 comments on commit 7382499

Please sign in to comment.