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 1610

Summary: Mix_HaltMusic does not call Music Finish Hook [patch]
Product: SDL_mixer Reporter: Gabriel Jacobo <gabomdq>
Component: miscAssignee: Gabriel Jacobo <gabomdq>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: jorgen
Version: unspecified   
Hardware: x86_64   
OS: Linux   
Attachments: Call Music Finish Hook from Mix_HaltMusic

Description Gabriel Jacobo 2012-09-27 06:03:26 UTC
Created attachment 959 [details]
Call Music Finish Hook from Mix_HaltMusic

The hook set up with Mix_HookMusicFinished is not being called when you issue a
Mix_HaltMusic, though it should according to the documentation:

"int Mix_HaltMusic()
Halt playback of music. This interrupts music fader effects. Any callback set
by Mix_HookMusicFinished will be called when the music stops."
Comment 1 Ryan C. Gordon 2013-01-03 07:21:32 UTC
This is hg changeset a4e9c53d9c30 for the 1.2 branch, and 131d1de92d4d for the default branch now, thanks!

--ryan.
Comment 2 Sam Lantinga 2013-02-11 20:58:34 UTC
This was intentionally not done back in the day, because it caused problems in Heroes III.  Not that it matters now, just FYI. :)
Comment 3 (disabled) Jørgen Tjernø 2014-04-19 01:13:21 UTC
This change broke documented functionality:

https://hg.libsdl.org/SDL_mixer/file/95e548111cc3/SDL_mixer.h#l210

"This callback is only called if the music finishes naturally."

Since there's no way to figure out if this call came from a Mix_HaltMusic call or a natural finish, the calling application now needs to set some global state before calling Mix_HaltMusic to be able to differentiate. >:|

I don't know if it's worth reverting, since this change was made over a year ago, but if nothing else the comments in SDL_mixer.h should be updated to reflect the changed functionality.
Comment 4 Sam Lantinga 2014-04-19 21:50:48 UTC
Good point. Gabriel, what was the motivation for this change?
Comment 5 Gabriel Jacobo 2014-04-19 22:41:06 UTC
The motivation is stated in my first comment on this bug, the doc for Mix_HaltMusic said it will call the callback, and it wasn't doing that.
So, there's a conflict in the documentation :)

I think it's best to leave it as is now, if you don't get a callback at all, the user can not work around this limitation without modifying the library code. However, if you do issue the callback and for some reason care about whether it was a manual stop or a "natural" stop, you can keep track of that with your own flag.

The docs will have to be fixed whatever alternative you end up choosing.
Comment 6 (disabled) Jørgen Tjernø 2014-04-21 20:03:00 UTC
I don't see where in the comments for Mix_HaltMusic it states that it'll call the hook, because it doesn't *have* any comments. The docs specify that behavior, but I have no idea where the docs are generated from: http://jcatki.no-ip.org:8080/SDL_mixer/SDL_mixer.html#SEC67


While ideally I would've seen us revert this change, since it changes functionality, it has been this way for over a year now, and changing behavior again is worse. Like you point out, at least there's a way to work around to get the old behavior with the new behavior.

Here's my comment update:

https://hg.libsdl.org/SDL_mixer/rev/99007f264b9c