From ed442f1aec81aa0d061fae3c342652db8ba17d1d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 3 May 2023 18:21:12 +0200 Subject: [PATCH] Crash with error code 2 for mixer --- src/audio.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/audio.c b/src/audio.c index 98866bc..9b6e33c 100644 --- a/src/audio.c +++ b/src/audio.c @@ -1,4 +1,5 @@ #include "../includes/audio.h" +#include // Stocke les données à propos de la musique static double average; @@ -16,13 +17,22 @@ void callback(void *_, Uint8 *stream, int size) { void initMusic(Mix_Music *music, const char *filename) { Mix_Init(MIX_INIT_MID); - Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 1024); - music = Mix_LoadMUS(filename); + if (Mix_OpenAudio(44100, AUDIO_S16LSB, 1, 1024)) { + fprintf(stderr, "Erreur Mix_OpenAudio\n"); + exit(2); + }; + if (!(music = Mix_LoadMUS(filename))) { + fprintf(stderr, "Erreur Mix_LoadMUS\n"); + exit(2); + } Mix_VolumeMusic(MIX_MAX_VOLUME / 10); Mix_SetPostMix(callback, NULL); - Mix_PlayMusic(music, 1); + if (Mix_PlayMusic(music, 1)) { + fprintf(stderr, "Erreur Mix_PlayMusic\n"); + exit(2); + }; } void freeMusic(Mix_Music *music) {