We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2706

Summary: Mix_PlayMusic broken logic when loop > 1
Product: SDL_mixer Reporter: Peter Kosyh <gl00my>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: sezeroz
Version: 2.0.0   
Hardware: All   
OS: All   

Description Peter Kosyh 2014-08-26 15:21:55 UTC
Hello!
This code in Mix_FadeInMusicPos
----------
    if (loops == 1) {
        /* Loop is the number of times to play the audio */
        loops = 0;
    }
-----------
and music_halt_or_loop:
-----------
       if (music_loops)
        {
            Mix_Fading current_fade;
            if (music_loops > 0) {
                --music_loops;
            }
            current_fade = music_playing->fading;
            music_internal_play(music_playing, 0.0);
            music_playing->fading = current_fade;
        }
-----------
makes loop parameter very strange.

Mix_PlayMusic(x, 1) -> will play 1 time
Mix_PlayMusic(x, 2) -> will play 3 time
Mix_PlayMusic(x, n) -> will play n+1 time

Can you tell me if it is bug or i will make workaround in my application?

May be right fix would be:

    if (loops > 0) {
        /* Loop is the number of times to play the audio */
        loops = loops - 1;
    }

WBR, Peter Kosyh
Comment 1 Sam Lantinga 2017-10-21 19:30:34 UTC
This is fixed in the latest version of SDL and SDL_mixer available in Mercurial:
http://hg.libsdl.org/

Thanks!
Comment 2 Ozkan Sezer 2019-09-05 20:11:50 UTC
In SDL-1.2 branch, I backported 2.0 commit bd8389c6dd as:
https://hg.libsdl.org/SDL_mixer/rev/b57842dc6349

... and then applied the fix suggested by Peter Kosyh as:
https://hg.libsdl.org/SDL_mixer/rev/c606c85c8863