From 67428372edad56021e8387058de736896a621995 Mon Sep 17 00:00:00 2001 From: shibbo Date: Wed, 8 Nov 2023 13:37:29 -0500 Subject: [PATCH 1/5] Return 0 when source actor doesn't exist due to being removed --- Fushigi/course/CourseLink.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Fushigi/course/CourseLink.cs b/Fushigi/course/CourseLink.cs index 85c68af4..9f293971 100644 --- a/Fushigi/course/CourseLink.cs +++ b/Fushigi/course/CourseLink.cs @@ -34,6 +34,11 @@ public BymlHashTable BuildNode() public ulong GetSrcHash() { + if (mSource == null) + { + return 0; + } + return mSource.GetHash(); } From 7e15d87abf02f87dc15938edb28a933b535c604b Mon Sep 17 00:00:00 2001 From: shibbo Date: Wed, 8 Nov 2023 14:40:54 -0500 Subject: [PATCH 2/5] properly delete Rails that are attached to objects --- Fushigi/course/CourseRail.cs | 11 +++++++++++ Fushigi/ui/CourseAreaEditContext.cs | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/Fushigi/course/CourseRail.cs b/Fushigi/course/CourseRail.cs index 4c0b9f3d..eaccc6cb 100644 --- a/Fushigi/course/CourseRail.cs +++ b/Fushigi/course/CourseRail.cs @@ -409,6 +409,17 @@ public CourseActorToRailLinks() } + public void RemoveLinkFromSrc(ulong hash) + { + foreach (Link link in mLinks) + { + if (link.Source.GetHash() == hash) + { + mLinks.RemoveAt(mLinks.IndexOf(link)); + } + } + } + public BymlArrayNode SerializeToArray() { BymlArrayNode node = new((uint)mLinks.Count); diff --git a/Fushigi/ui/CourseAreaEditContext.cs b/Fushigi/ui/CourseAreaEditContext.cs index 6185f9c0..642119a4 100644 --- a/Fushigi/ui/CourseAreaEditContext.cs +++ b/Fushigi/ui/CourseAreaEditContext.cs @@ -136,6 +136,7 @@ public void DeleteActor(CourseActor actor) DeleteActorFromGroups(actor.GetHash()); DeleteLinksWithSrcHash(actor.GetHash()); DeleteLinksWithDestHash(actor.GetHash()); + DeleteRail(actor.GetHash()); mUndoHandler.AddToUndo(area.mActorHolder.GetActors() .RevertableRemove(actor, $"Removing {actor.mActorName}")); } @@ -190,5 +191,11 @@ public CourseActorHolder GetActorHolder() { return area.mActorHolder; } + + public void DeleteRail(ulong hash) + { + Console.WriteLine($"Removing Rail attached to {hash}"); + area.mRailLinks.RemoveLinkFromSrc(hash); + } } } From b581ea57cf0c23ea6e81cbe5c7d0b0d05228052e Mon Sep 17 00:00:00 2001 From: shibbo Date: Wed, 8 Nov 2023 14:43:44 -0500 Subject: [PATCH 3/5] oops --- Fushigi/course/CourseRail.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Fushigi/course/CourseRail.cs b/Fushigi/course/CourseRail.cs index eaccc6cb..23edd8fd 100644 --- a/Fushigi/course/CourseRail.cs +++ b/Fushigi/course/CourseRail.cs @@ -411,13 +411,20 @@ public CourseActorToRailLinks() public void RemoveLinkFromSrc(ulong hash) { + int idx = -1; foreach (Link link in mLinks) { if (link.Source.GetHash() == hash) { - mLinks.RemoveAt(mLinks.IndexOf(link)); + idx = mLinks.IndexOf(link); + break; } } + + if (idx != -1) + { + mLinks.RemoveAt(idx); + } } public BymlArrayNode SerializeToArray() From 3ec637af1de37b44f26b56575dceb9e39d39874e Mon Sep 17 00:00:00 2001 From: shibbo Date: Wed, 8 Nov 2023 14:47:59 -0500 Subject: [PATCH 4/5] Properly handle object attributes when the destination actor no longer exists --- Fushigi/ui/widgets/CourseScene.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Fushigi/ui/widgets/CourseScene.cs b/Fushigi/ui/widgets/CourseScene.cs index 846fe442..41b3b161 100644 --- a/Fushigi/ui/widgets/CourseScene.cs +++ b/Fushigi/ui/widgets/CourseScene.cs @@ -422,9 +422,19 @@ private void SelectionParameterPanel() CourseActor? destActor = selectedArea.mActorHolder[hashArray[i]]; - if (ImGui.Button(destActor.mName)) + if (destActor != null) { + if (ImGui.Button(destActor.mName)) + { + + } + } + else + { + if (ImGui.Button("Actor Not Found")) + { + } } ImGui.NextColumn(); From f2a291dcb38e34b79ce8a0231619584191e86ecc Mon Sep 17 00:00:00 2001 From: shibbo Date: Wed, 8 Nov 2023 14:57:11 -0500 Subject: [PATCH 5/5] yet another safeguard from Link crashes --- Fushigi/course/CourseLink.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Fushigi/course/CourseLink.cs b/Fushigi/course/CourseLink.cs index 9f293971..458ef9af 100644 --- a/Fushigi/course/CourseLink.cs +++ b/Fushigi/course/CourseLink.cs @@ -82,6 +82,16 @@ public bool IsDestValid(CourseActorHolder actorHolder) return actorHolder.HasHash(mDest.GetHash()); } + public bool IsSourceActorExist() + { + return mSource != null; + } + + public bool IsDestActorExist() + { + return mDest != null; + } + CourseActor? mSource; CourseActor? mDest; string mLinkName; @@ -215,11 +225,14 @@ public bool IsAnyLinkInvalid(CourseActorHolder holder) public BymlArrayNode SerializeToArray() { - BymlArrayNode node = new((uint)mLinks.Count); + BymlArrayNode node = new(); foreach(CourseLink link in mLinks) { - node.AddNodeToArray(link.BuildNode()); + if (link.IsSourceActorExist() && link.IsDestActorExist()) + { + node.AddNodeToArray(link.BuildNode()); + } } return node;