Currently, when race-specific space music is enabled and you enter the interplanetary view (from loading, orbit, an encounter, or hyperspace), playSpaceMusic reloads the space music without first freeing it if it's already loaded. This leaks:
the normal space music loaded by LoadIPData if this is the first time space music is being played since the solar system was initialized
the space music previously loaded by playSpaceMusic if it isn't being called for the first time since the solar system was initialized (happens when leaving a planet)
At least when using the PC music (I didn't test it with .ogg music), this eventually nearly fills up MikMod's sample storage, preventing most .mods from being loaded (it also leaks memory, but not a very large amount, since .mods are relatively small in memory).
This PR fixes the issue by loading all space music in playSpaceMusic, and only if no space music is already loaded.
It also removes the calls to playSpaceMusic when a game is about to be loaded or started - I'm not very experienced with UQM's codebase, so correct me if I'm wrong, but I'm pretty sure they aren't needed: playSpaceMusic should always be called by ResetSolarSys when you're entering the interplanetary view, regardless of whether or not it's due to loading a game. Therefore, the music these calls play should always be immediately overridden by whatever music the loaded game plays. They were also causing another leak when loading from outside a solar system (as FreeIPData is never called to free the music that they load). I tested saving/loading at multiple races' systems/planets several times after this change and didn't run into an issue.
(I'm not sure whether I should mention this here, and you might know this already, but on an unrelated note, cf82472 seems to have broken movement controls in battle and hyperspace; I had to revert it (without committing) to test this.)
Currently, when race-specific space music is enabled and you enter the interplanetary view (from loading, orbit, an encounter, or hyperspace),
playSpaceMusic
reloads the space music without first freeing it if it's already loaded. This leaks:LoadIPData
if this is the first time space music is being played since the solar system was initializedplaySpaceMusic
if it isn't being called for the first time since the solar system was initialized (happens when leaving a planet)At least when using the PC music (I didn't test it with .ogg music), this eventually nearly fills up MikMod's sample storage, preventing most .mods from being loaded (it also leaks memory, but not a very large amount, since .mods are relatively small in memory).
This PR fixes the issue by loading all space music in
playSpaceMusic
, and only if no space music is already loaded.It also removes the calls to
playSpaceMusic
when a game is about to be loaded or started - I'm not very experienced with UQM's codebase, so correct me if I'm wrong, but I'm pretty sure they aren't needed:playSpaceMusic
should always be called byResetSolarSys
when you're entering the interplanetary view, regardless of whether or not it's due to loading a game. Therefore, the music these calls play should always be immediately overridden by whatever music the loaded game plays. They were also causing another leak when loading from outside a solar system (asFreeIPData
is never called to free the music that they load). I tested saving/loading at multiple races' systems/planets several times after this change and didn't run into an issue.(I'm not sure whether I should mention this here, and you might know this already, but on an unrelated note, cf82472 seems to have broken movement controls in battle and hyperspace; I had to revert it (without committing) to test this.)