Merge pull request #4 from UncleDanny/music-crash-fix

Appears to fix the mod unload crash in all cases. Needs more rigorous testing including music box, etc.
This commit is contained in:
Cameron Ewell authored and GitHub committed 2020-06-04 17:27:19 -04:00
commit 0b7595e3ec
2 files changed
+7 -6

No files matched your search

+6 -5
View File
@@ -138,7 +138,9 @@ namespace CalamityModMusic
public override void Unload()
{
IL.Terraria.Main.UpdateAudio -= TitleMusicIL;
customTitleMusicSlot = MusicID.Title;
Close();
titleMusicStopped?.Set();
Instance = null;
titleMusicStopped = null;
@@ -345,12 +347,11 @@ namespace CalamityModMusic
public override void Close()
{
// Close isn't called on the main thread. Who doesn't love a bit of thread safety
// Close may be called even if we didn't reach PostSetupContent, so don't try and stop a music track which hasn't been loaded or played
if (!Main.dedServ && customTitleMusicSlot > 0)
var slot = GetSoundSlot(SoundType.Music, "Sounds/Music/Calamity");
if (Main.music.IndexInRange(slot) && Main.music[slot]?.IsPlaying == true)
{
stopTitleMusic = true;
titleMusicStopped.WaitOne();
Main.music[slot].Stop(AudioStopOptions.Immediate);
}
base.Close();
}
+1 -1
View File
@@ -1,5 +1,5 @@
author = Fabsol and the Dev Team
version = 1.4.4.004
version = 1.4.4.005
displayName = Calamity Mod Music
homepage = https://forums.terraria.org/index.php?threads/calamity-mod.44065/
hideCode = true