SDL_mixer: Updated for SDL3 change of SDL_SetError returning SDL_FALSE, not -1

From 46ad68a77159fecdda43e04b4436d17b20d88d75 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 27 Aug 2024 22:39:04 +0300
Subject: [PATCH] Updated for SDL3 change of SDL_SetError returning SDL_FALSE,
 not -1

---
 src/codecs/mp3utils.c         |  3 ++-
 src/codecs/music_cmd.c        |  3 ++-
 src/codecs/music_drflac.c     |  3 ++-
 src/codecs/music_flac.c       |  9 ++++---
 src/codecs/music_fluidsynth.c |  3 ++-
 src/codecs/music_gme.c        |  6 +++--
 src/codecs/music_mpg123.c     | 15 +++++++----
 src/codecs/music_ogg.c        |  3 ++-
 src/codecs/music_opus.c       |  3 ++-
 src/codecs/music_wav.c        | 48 +++++++++++++++++++++++------------
 src/codecs/music_wavpack.c    |  3 ++-
 src/mixer.c                   |  9 ++++---
 src/music.c                   | 12 ++++++---
 13 files changed, 80 insertions(+), 40 deletions(-)

diff --git a/src/codecs/mp3utils.c b/src/codecs/mp3utils.c
index 57300aac..2b822ef4 100644
--- a/src/codecs/mp3utils.c
+++ b/src/codecs/mp3utils.c
@@ -41,7 +41,8 @@ int MP3_IOinit(struct mp3file_t *fil, SDL_IOStream *src) {
     fil->length = SDL_SeekIO(src, 0, SDL_IO_SEEK_END) - fil->start;
     fil->pos = 0;
     if (fil->start < 0 || fil->length < 0) {
-        return Mix_SetError("Error seeking in datastream");
+        Mix_SetError("Error seeking in datastream");
+        return -1;
     }
     SDL_SeekIO(src, fil->start, SDL_IO_SEEK_SET);
     return 0;
diff --git a/src/codecs/music_cmd.c b/src/codecs/music_cmd.c
index 6e16e454..5c720b42 100644
--- a/src/codecs/music_cmd.c
+++ b/src/codecs/music_cmd.c
@@ -167,7 +167,8 @@ static int MusicCMD_Play(void *context, int play_count)
     switch(music->pid) {
     /* Failed fork() system call */
     case -1:
-        return Mix_SetError("fork() failed");
+        Mix_SetError("fork() failed");
+        return -1;
 
     /* Child process - executes here */
     case 0: {
diff --git a/src/codecs/music_drflac.c b/src/codecs/music_drflac.c
index 3614af08..1bcf114f 100644
--- a/src/codecs/music_drflac.c
+++ b/src/codecs/music_drflac.c
@@ -262,7 +262,8 @@ static int DRFLAC_GetSome(void *context, void *data, int bytes, SDL_bool *done)
 
     if (music->loop_flag) {
         if (!drflac_seek_to_pcm_frame(music->dec, music->loop_start)) {
-            return Mix_SetError("drflac_seek_to_pcm_frame() failed");
+            Mix_SetError("drflac_seek_to_pcm_frame() failed");
+            return -1;
         } else {
             int play_count = -1;
             if (music->play_count > 0) {
diff --git a/src/codecs/music_flac.c b/src/codecs/music_flac.c
index 223c66b8..b0a1d3a2 100644
--- a/src/codecs/music_flac.c
+++ b/src/codecs/music_flac.c
@@ -654,7 +654,8 @@ static int FLAC_GetSome(void *context, void *data, int bytes, SDL_bool *done)
     }
 
     if (!flac.FLAC__stream_decoder_process_single(music->flac_decoder)) {
-        return Mix_SetError("FLAC__stream_decoder_process_single() failed");
+        Mix_SetError("FLAC__stream_decoder_process_single() failed");
+        return -1;
     }
 
     if (music->loop_flag) {
@@ -662,7 +663,8 @@ static int FLAC_GetSome(void *context, void *data, int bytes, SDL_bool *done)
         if (flac.FLAC__stream_decoder_seek_absolute(music->flac_decoder, (FLAC__uint64)music->loop_start) ==
                 FLAC__STREAM_DECODER_SEEK_ERROR) {
             flac.FLAC__stream_decoder_flush(music->flac_decoder);
-            return Mix_SetError("FLAC__stream_decoder_seek_absolute() failed");
+            Mix_SetError("FLAC__stream_decoder_seek_absolute() failed");
+            return -1;
         } else {
             int play_count = -1;
             if (music->play_count > 0) {
@@ -711,7 +713,8 @@ static int FLAC_Seek(void *context, double position)
             flac.FLAC__stream_decoder_flush(music->flac_decoder);
         }
 
-        return Mix_SetError("Seeking of FLAC stream failed: libFLAC seek failed.");
+        Mix_SetError("Seeking of FLAC stream failed: libFLAC seek failed.");
+        return -1;
     }
     return 0;
 }
diff --git a/src/codecs/music_fluidsynth.c b/src/codecs/music_fluidsynth.c
index 3041d3d9..a3659522 100644
--- a/src/codecs/music_fluidsynth.c
+++ b/src/codecs/music_fluidsynth.c
@@ -311,7 +311,8 @@ static int FLUIDSYNTH_GetSome(void *context, void *data, int bytes, SDL_bool *do
     }
 
     if (music->synth_write(music->synth, 4096/*music_spec.samples*/, music->buffer, 0, 2, music->buffer, 1, 2) != FLUID_OK) {
-        return Mix_SetError("Error generating FluidSynth audio");
+        Mix_SetError("Error generating FluidSynth audio");
+        return -1;
     }
     if (!SDL_PutAudioStreamData(music->stream, music->buffer, music->buffer_size)) {
         return -1;
diff --git a/src/codecs/music_gme.c b/src/codecs/music_gme.c
index 41aa9f72..068582c7 100644
--- a/src/codecs/music_gme.c
+++ b/src/codecs/music_gme.c
@@ -161,7 +161,8 @@ static int initialize_from_track_info(GME_Music *music, int track)
 
     err = gme.gme_track_info(music->game_emu, &musInfo, track);
     if (err != 0) {
-        return Mix_SetError("GME: %s", err);
+        Mix_SetError("GME: %s", err);
+        return -1;
     }
 
     music->track_length = musInfo->length;
@@ -397,7 +398,8 @@ static int GME_StartTrack(void *music_p, int track)
 
     err = gme.gme_start_track(music->game_emu, track);
     if (err != 0) {
-        return Mix_SetError("GME: %s", err);
+        Mix_SetError("GME: %s", err);
+        return -1;
     }
 
     GME_Play(music, music->play_count);
diff --git a/src/codecs/music_mpg123.c b/src/codecs/music_mpg123.c
index 629d4611..487b63d3 100644
--- a/src/codecs/music_mpg123.c
+++ b/src/codecs/music_mpg123.c
@@ -225,7 +225,8 @@ static int MPG123_Open(const SDL_AudioSpec *spec)
 {
     (void)spec;
     if (mpg123.mpg123_init() != MPG123_OK) {
-        return Mix_SetError("mpg123_init() failed");
+        Mix_SetError("mpg123_init() failed");
+        return -1;
     }
     return 0;
 }
@@ -397,7 +398,8 @@ static int MPG123_GetSome(void *context, void *data, int bytes, SDL_bool *done)
     case MPG123_NEW_FORMAT:
         result = mpg123.mpg123_getformat(music->handle, &rate, &channels, &encoding);
         if (result != MPG123_OK) {
-            return Mix_SetError("mpg123_getformat: %s", mpg_err(music->handle, result));
+            Mix_SetError("mpg123_getformat: %s", mpg_err(music->handle, result));
+            return -1;
         }
 #ifdef DEBUG_MPG123
         printf("MPG123 format: %s, channels: %d, rate: %ld\n",
@@ -443,7 +445,8 @@ static int MPG123_GetSome(void *context, void *data, int bytes, SDL_bool *done)
         }
         break;
     default:
-        return Mix_SetError("mpg123_read: %s", mpg_err(music->handle, result));
+        Mix_SetError("mpg123_read: %s", mpg_err(music->handle, result));
+        return -1;
     }
     return 0;
 }
@@ -459,7 +462,8 @@ static int MPG123_Seek(void *context, double secs)
     off_t offset = (off_t)(music->sample_rate * secs);
 
     if ((offset = mpg123.mpg123_seek(music->handle, offset, SEEK_SET)) < 0) {
-        return Mix_SetError("mpg123_seek: %s", mpg_err(music->handle, (int)-offset));
+        Mix_SetError("mpg123_seek: %s", mpg_err(music->handle, (int)-offset));
+        return -1;
     }
     return 0;
 }
@@ -472,7 +476,8 @@ static double MPG123_Tell(void *context)
         return 0.0;
     }
     if ((offset = mpg123.mpg123_tell(music->handle)) < 0) {
-        return Mix_SetError("mpg123_tell: %s", mpg_err(music->handle, (int)-offset));
+        Mix_SetError("mpg123_tell: %s", mpg_err(music->handle, (int)-offset));
+        return -1.0;
     }
     return (double)offset / music->sample_rate;
 }
diff --git a/src/codecs/music_ogg.c b/src/codecs/music_ogg.c
index 255ebb42..1877f0eb 100644
--- a/src/codecs/music_ogg.c
+++ b/src/codecs/music_ogg.c
@@ -202,7 +202,8 @@ static int OGG_UpdateSection(OGG_music *music)
 
     vi = vorbis.ov_info(&music->vf, -1);
     if (!vi) {
-        return Mix_SetError("ov_info returned NULL");
+        Mix_SetError("ov_info returned NULL");
+        return -1;
     }
 
     if (vi->channels == music->vi.channels && vi->rate == music->vi.rate) {
diff --git a/src/codecs/music_opus.c b/src/codecs/music_opus.c
index 03d577e3..eaeb76a0 100644
--- a/src/codecs/music_opus.c
+++ b/src/codecs/music_opus.c
@@ -173,7 +173,8 @@ static int OPUS_UpdateSection(OPUS_music *music)
 
     op_info = opus.op_head(music->of, -1);
     if (!op_info) {
-        return Mix_SetError("op_head returned NULL");
+        Mix_SetError("op_head returned NULL");
+        return -1;
     }
 
     if (music->op_info && op_info->channel_count == music->op_info->channel_count) {
diff --git a/src/codecs/music_wav.c b/src/codecs/music_wav.c
index 4b9783c8..b0f79420 100644
--- a/src/codecs/music_wav.c
+++ b/src/codecs/music_wav.c
@@ -455,23 +455,27 @@ static int MS_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Uin
      * about supporting more than stereo anyway.
      */
     if (channels > 2) {
-        return Mix_SetError("Invalid number of channels");
+        Mix_SetError("Invalid number of channels");
+        return -1;
     }
 
     if (bitspersample != 4) {
-        return Mix_SetError("Invalid MS ADPCM bits per sample of %u", (unsigned int)bitspersample);
+        Mix_SetError("Invalid MS ADPCM bits per sample of %u", (unsigned int)bitspersample);
+        return -1;
     }
 
     /* The block size must be big enough to contain the block header. */
     if (blockalign < blockheadersize) {
-        return Mix_SetError("Invalid MS ADPCM block size (nBlockAlign)");
+        Mix_SetError("Invalid MS ADPCM block size (nBlockAlign)");
+        return -1;
     }
 
     /* There are wSamplesPerBlock, wNumCoef, and at least 7 coefficient pairs in
      * the extended part of the header.
      */
     if (chunk_length < 22) {
-        return Mix_SetError("Could not read MS ADPCM format header");
+        Mix_SetError("Could not read MS ADPCM format header");
+        return -1;
     }
 
     cbExtSize = SDL_Swap16LE(fmt->cbSize);
@@ -487,11 +491,14 @@ static int MS_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Uin
     }
 
     if (chunk_length < 22 + coeffcount * 4) {
-        return Mix_SetError("Could not read custom coefficients in MS ADPCM format header");
+        Mix_SetError("Could not read custom coefficients in MS ADPCM format header");
+        return -1;
     } else if (cbExtSize < 4 + coeffcount * 4) {
-        return Mix_SetError("Invalid MS ADPCM format header (too small)");
+        Mix_SetError("Invalid MS ADPCM format header (too small)");
+        return -1;
     } else if (coeffcount < 7) {
-        return Mix_SetError("Missing required coefficients in MS ADPCM format header");
+        Mix_SetError("Missing required coefficients in MS ADPCM format header");
+        return -1;
     }
 
     coeffdata = (MS_ADPCM_CoeffData *)SDL_malloc(sizeof(MS_ADPCM_CoeffData) + coeffcount * 4);
@@ -509,7 +516,8 @@ static int MS_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Uin
             c -= 0x10000;
         }
         if (i < 14 && c != presetcoeffs[i]) {
-            return Mix_SetError("Wrong preset coefficients in MS ADPCM format header");
+            Mix_SetError("Wrong preset coefficients in MS ADPCM format header");
+            return -1;
         }
         coeffdata->coeff[i] = (Sint16)c;
     }
@@ -537,7 +545,8 @@ static int MS_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Uin
      * A truncated block header with just one sample is not supported.
      */
     if (samplesperblock == 1 || blockdatasamples < (size_t)(samplesperblock - 2)) {
-        return Mix_SetError("Invalid number of samples per MS ADPCM block (wSamplesPerBlock)");
+        Mix_SetError("Invalid number of samples per MS ADPCM block (wSamplesPerBlock)");
+        return -1;
     }
 
     state->blocksize = blockalign;
@@ -614,7 +623,8 @@ static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
     MS_ADPCM_CoeffData *ddata = (MS_ADPCM_CoeffData *)state->ddata;
 
     if (state->block.size < state->blockheadersize) {
-        return Mix_SetError("Invalid ADPCM header");
+        Mix_SetError("Invalid ADPCM header");
+        return -1;
     }
 
     for (c = 0; c < channels; c++) {
@@ -623,7 +633,8 @@ static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
         /* Load the coefficient pair into the channel state. */
         coeffindex = state->block.data[o];
         if (coeffindex > ddata->coeffcount) {
-            return Mix_SetError("Invalid MS ADPCM coefficient index in block header");
+            Mix_SetError("Invalid MS ADPCM coefficient index in block header");
+            return -1;
         }
         cstate[c].coeff1 = ddata->coeff[coeffindex * 2];
         cstate[c].coeff2 = ddata->coeff[coeffindex * 2 + 1];
@@ -725,16 +736,19 @@ static int IMA_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Ui
 
     /* IMA ADPCM can also have 3-bit samples, but it's not supported by SDL at this time. */
     if (bitspersample == 3) {
-        return Mix_SetError("3-bit IMA ADPCM currently not supported");
+        Mix_SetError("3-bit IMA ADPCM currently not supported");
+        return -1;
     } else if (bitspersample != 4) {
-        return Mix_SetError("Invalid IMA ADPCM bits per sample of %u", (unsigned int)bitspersample);
+        Mix_SetError("Invalid IMA ADPCM bits per sample of %u", (unsigned int)bitspersample);
+        return -1;
     }
 
     /* The block size is required to be a multiple of 4 and it must be able to
      * hold a block header.
      */
     if (blockalign < blockheadersize || blockalign % 4) {
-        return Mix_SetError("Invalid IMA ADPCM block size (nBlockAlign)");
+        Mix_SetError("Invalid IMA ADPCM block size (nBlockAlign)");
+        return -1;
     }
 
     if (formattag == EXTENSIBLE_CODE) {
@@ -767,7 +781,8 @@ static int IMA_ADPCM_Init(ADPCM_DecoderState *state, const Uint8 *chunk_data, Ui
      * not enforced here as there are no compatibility issues.
      */
     if (blockdatasamples < (size_t)(samplesperblock - 1)) {
-        return Mix_SetError("Invalid number of samples per IMA ADPCM block (wSamplesPerBlock)");
+        Mix_SetError("Invalid number of samples per IMA ADPCM block (wSamplesPerBlock)");
+        return -1;
     }
 
     state->blocksize = blockalign;
@@ -874,7 +889,8 @@ static int IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state)
     Uint8 *cstate = (Uint8 *)state->cstate;
 
     if (state->block.size < state->blockheadersize) {
-        return Mix_SetError("Invalid ADPCM header");
+        Mix_SetError("Invalid ADPCM header");
+        return -1;
     }
 
     for (c = 0; c < state->channels; c++) {
diff --git a/src/codecs/music_wavpack.c b/src/codecs/music_wavpack.c
index aa5afc77..ac609201 100644
--- a/src/codecs/music_wavpack.c
+++ b/src/codecs/music_wavpack.c
@@ -588,7 +588,8 @@ static int WAVPACK_Seek(void *context, double time)
                    wvpk.WavpackSeekSample64(music->ctx, sample) :
                    wvpk.WavpackSeekSample(music->ctx, (uint32_t)sample);
     if (!success) {
-        return Mix_SetError("%s", wvpk.WavpackGetErrorMessage(music->ctx));
+        Mix_SetError("%s", wvpk.WavpackGetErrorMessage(music->ctx));
+        return -1;
     }
     #ifdef MUSIC_WAVPACK_DSD
     if (music->decimation_ctx) {
diff --git a/src/mixer.c b/src/mixer.c
index 129d02e1..716d5606 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -1068,10 +1068,12 @@ int Mix_PlayChannelTimed(int which, Mix_Chunk *chunk, int loops, int ticks)
 
     /* Don't play null pointers :-) */
     if (chunk == NULL) {
-        return Mix_SetError("Tried to play a NULL chunk");
+        Mix_SetError("Tried to play a NULL chunk");
+        return -1;
     }
     if (!checkchunkintegral(chunk)) {
-        return Mix_SetError("Tried to play a chunk with a bad frame");
+        Mix_SetError("Tried to play a chunk with a bad frame");
+        return -1;
     }
 
     /* Lock the mixer while modifying the playing channels */
@@ -1147,7 +1149,8 @@ int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int t
         return -1;
     }
     if (!checkchunkintegral(chunk)) {
-        return Mix_SetError("Tried to play a chunk with a bad frame");
+        Mix_SetError("Tried to play a chunk with a bad frame");
+        return -1;
     }
 
     /* Lock the mixer while modifying the playing channels */
diff --git a/src/music.c b/src/music.c
index 1796ef5a..4a2ebbe2 100644
--- a/src/music.c
+++ b/src/music.c
@@ -945,12 +945,14 @@ int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)
     int retval;
 
     if (ms_per_step == 0) {
-        return Mix_SetError("Audio device hasn't been opened");
+        Mix_SetError("Audio device hasn't been opened");
+        return -1;
     }
 
     /* Don't play null pointers :-) */
     if (music == NULL) {
-        return Mix_SetError("music parameter was NULL");
+        Mix_SetError("music parameter was NULL");
+        return -1;
     }
 
     /* Setup the data */
@@ -1343,7 +1345,8 @@ int Mix_StartTrack(Mix_Music *music, int track)
         }
         result = music->interface->StartTrack(music->context, track);
     } else {
-        result = Mix_SetError("That operation is not supported");
+        Mix_SetError("That operation is not supported");
+        result = -1;
     }
     Mix_UnlockAudio();
 
@@ -1358,7 +1361,8 @@ int Mix_GetNumTracks(Mix_Music *music)
     if (music && music->interface->GetNumTracks) {
         result = music->interface->GetNumTracks(music->context);
     } else {
-        result = Mix_SetError("That operation is not supported");
+        Mix_SetError("That operation is not supported");
+        result = -1;
     }
     Mix_UnlockAudio();
     return result;