Clean previously created data when exiting in init_SDL()

This commit is contained in:
Franck STAUFFER 2020-08-04 09:02:24 +02:00
parent 3b0b343337
commit 53446c190b
Signed by: franck.stauffer
GPG Key ID: AAF5A94045CEC261
1 changed files with 10 additions and 0 deletions

View File

@ -110,17 +110,23 @@ init_SDL(const char* path)
if (!w) {
fputs("ERROR: Failed to create a window\n", stderr);
SDL_Quit();
return 0;
}
s = SDL_GetWindowSurface(w);
if (!s) {
fputs("ERROR: Failed to get window's surface\n", stderr);
SDL_DestroyWindow(w);
SDL_Quit();
return 0;
}
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 1024)) {
fputs("ERROR: Failed to open audio\n", stderr);
SDL_FreeSurface(s);
SDL_DestroyWindow(w);
SDL_Quit();
return 0;
}
@ -130,6 +136,10 @@ init_SDL(const char* path)
buzzer = Mix_LoadWAV("resources/buzzer.wav");
if (!buzzer) {
fputs("ERROR: Failed to load sound effects\n", stderr);
Mix_Quit();
SDL_FreeSurface(s);
SDL_DestroyWindow(w);
SDL_Quit();
return 0;
}