From 43e40ae84913738117f07c0764d9feae5ebaa7b1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 23 Aug 2014 10:57:26 -0700 Subject: [PATCH] Fixed bug 2690 - Floating point exception in Mix_Volume() Francisco de la Pe?a This happens rarely under uncertain circunstances, as it doesn't crash always and does it randomly. Fortunately, I've got a backtrace when running a GDB session. Might be a divide by zero issue in SDL or SDL_mixer. Program received signal SIGFPE, Arithmetic exception. 0x00000038e8c08a7d in mix_channels (udata=, stream=0x24e11b0 "", len=2048) at mixer.c:345 345 Mix_Volume(i, (mix_channel[i].fade_volume * ticks) / mix_channel[i].fade_length ); (gdb) bt f #0 0x00000038e8c08a7d in mix_channels (udata=, stream=0x24e11b0 "", len=2048) at mixer.c:345 ticks = 0 mix_input = i = 0 mixable = volume = sdl_ticks = 129373 Using SDL 2.0.3 and SDL_Mixer 2.0.0, PulseAudio, Fedora 20 x86_64 but looks like can be reproduced on other platforms. --- mixer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mixer.c b/mixer.c index 2eaf1642..a1bc6916 100644 --- a/mixer.c +++ b/mixer.c @@ -320,7 +320,7 @@ static void mix_channels(void *udata, Uint8 *stream, int len) /* Mix any playing channels... */ sdl_ticks = SDL_GetTicks(); for ( i=0; i 0 && mix_channel[i].expire < sdl_ticks ) { /* Expiration delay for that channel is reached */ mix_channel[i].playing = 0; @@ -330,7 +330,7 @@ static void mix_channels(void *udata, Uint8 *stream, int len) _Mix_channel_done_playing(i); } else if ( mix_channel[i].fading != MIX_NO_FADING ) { Uint32 ticks = sdl_ticks - mix_channel[i].ticks_fade; - if( ticks > mix_channel[i].fade_length ) { + if ( ticks >= mix_channel[i].fade_length ) { Mix_Volume(i, mix_channel[i].fade_volume_reset); /* Restore the volume */ if( mix_channel[i].fading == MIX_FADING_OUT ) { mix_channel[i].playing = 0; @@ -340,7 +340,7 @@ static void mix_channels(void *udata, Uint8 *stream, int len) } mix_channel[i].fading = MIX_NO_FADING; } else { - if( mix_channel[i].fading == MIX_FADING_OUT ) { + if ( mix_channel[i].fading == MIX_FADING_OUT ) { Mix_Volume(i, (mix_channel[i].fade_volume * (mix_channel[i].fade_length-ticks)) / mix_channel[i].fade_length ); } else { @@ -1094,7 +1094,7 @@ int Mix_FadeOutChannel(int which, int ms) (mix_channel[which].fading != MIX_FADING_OUT) ) { mix_channel[which].fade_volume = mix_channel[which].volume; mix_channel[which].fading = MIX_FADING_OUT; - mix_channel[which].fade_length = ms; + mix_channel[which].fade_length = (Uint32)ms; mix_channel[which].ticks_fade = SDL_GetTicks(); /* only change fade_volume_reset if we're not fading. */