JHGuitarFreak / UQM-MegaMod-Archived

UQM-HD Remastered plus a whole host of extra content and goodies
http://megamod.serosis.net
Other
21 stars 1 forks source link

Fix space music resource leaks #21

Closed Ala-lala closed 5 years ago

Ala-lala commented 5 years ago

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:

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.)

Serosis commented 5 years ago

Thanks for another fix!

as for cf82472 I didn't notice it until you said something. I'll peck at it some more to see if I can't get it to work the way it's supposed to.