Skip to content

Commit

Permalink
Fixed bug 2690 - Floating point exception in Mix_Volume()
Browse files Browse the repository at this point in the history
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=<optimized out>, 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=<optimized out>, stream=0x24e11b0 "", len=2048) at mixer.c:345
        ticks = 0
        mix_input = <optimized out>
        i = 0
        mixable = <optimized out>
        volume = <optimized out>
        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.
  • Loading branch information
slouken committed Aug 23, 2014
1 parent 6cb06bc commit 43e40ae
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mixer.c
Expand Up @@ -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<num_channels; ++i ) {
if( ! mix_channel[i].paused ) {
if ( !mix_channel[i].paused ) {
if ( mix_channel[i].expire > 0 && mix_channel[i].expire < sdl_ticks ) {
/* Expiration delay for that channel is reached */
mix_channel[i].playing = 0;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 43e40ae

Please sign in to comment.