diff --git a/UndertaleModLib/Models/UndertaleGameObject.cs b/UndertaleModLib/Models/UndertaleGameObject.cs index 2868d41f4..ccc7e109c 100644 --- a/UndertaleModLib/Models/UndertaleGameObject.cs +++ b/UndertaleModLib/Models/UndertaleGameObject.cs @@ -209,6 +209,7 @@ public void Serialize(UndertaleWriter writer) { v.Serialize(writer); } + FixEvents(); writer.WriteUndertaleObject(Events); } @@ -259,6 +260,24 @@ public void Unserialize(UndertaleReader reader) Events = reader.ReadUndertaleObject>>(); } + /// + /// It is possible to create a new event in the UndertaleModTool GUI that has no actions. + /// Events with zero actions will lead to a segfault in the runner when loading chunk OBJT, + /// because it assumes there is at least one action per event. + /// This has been proven on Undertale 1.01, maybe modern runners are not affected. + /// + /// This method removes these empty events. + /// + private void FixEvents() { + foreach (UndertalePointerList events in Events) { + for (int i = events.Count - 1; i >= 0; i--) { + if (events[i].Actions.Count == 0) { + events.RemoveAt(i); + } + } + } + } + /// public static uint UnserializeChildObjectCount(UndertaleReader reader) { @@ -1717,4 +1736,4 @@ public enum EventSubtypeGesture : uint /// The global rotate end event. /// GlobalRotateEnd = 76, -} \ No newline at end of file +}