From f06e2d86da623912c87f54ab6d887bb3e8541b2a Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 6 Sep 2015 13:23:11 -0400 Subject: [PATCH] TasStateManager - fix crashes when deleting and updating branches, these are all probably hacks that need to be revisisted --- .../movie/tasproj/TasStateManager.cs | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index 8e3d81cd1d..20819d4eaa 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -712,6 +712,15 @@ namespace BizHawk.Client.Common stateToMatch = States[frame]; else { + // ************************** + // adelikat: If you remove branches, keyNotFound exceptions occur here, I have no idea if this is okay to do, but it makes them go away + // Repro steps, remove this code and then: start a project, advance some frames, save branch, advance further, save another one, advance again, save. removing the first branch + if (!BranchStates.ContainsKey(frame)) + return -2; + if (!BranchStates[frame].ContainsKey(branch)) + return -2; + // ************************** + stateToMatch = BranchStates[frame][branch]; if (States.ContainsKey(frame) && States[frame] == stateToMatch) return -1; @@ -775,10 +784,13 @@ namespace BizHawk.Client.Common if (stateHasDuplicate(kvp.Key, index) == -2) { - if (stateList[index].IsOnDisk) - { } - else - Used -= (ulong)stateList[index].Length; + if (stateList.ContainsKey(index)) // adelikat: more containsKey checking, see stateHasDuplicate code for details + { + if (stateList[index].IsOnDisk) + { } + else + Used -= (ulong)stateList[index].Length; + } } stateList.Remove(index); @@ -801,10 +813,13 @@ namespace BizHawk.Client.Common if (stateHasDuplicate(kvp.Key, index) == -2) { - if (stateList[index].IsOnDisk) - { } - else - Used -= (ulong)stateList[index].Length; + if (stateList.ContainsKey(index)) // adelikat: more containsKey checking, see stateHasDuplicate code for details + { + if (stateList[index].IsOnDisk) + { } + else + Used -= (ulong)stateList[index].Length; + } } stateList.Remove(index);