Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion UndertaleModLib/Models/UndertaleGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public void Serialize(UndertaleWriter writer)
{
v.Serialize(writer);
}
FixEvents();
writer.WriteUndertaleObject(Events);
}

Expand Down Expand Up @@ -259,6 +260,24 @@ public void Unserialize(UndertaleReader reader)
Events = reader.ReadUndertaleObject<UndertalePointerList<UndertalePointerList<Event>>>();
}

/// <summary>
/// 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.
/// </summary>
private void FixEvents() {
foreach (UndertalePointerList<Event> events in Events) {
for (int i = events.Count - 1; i >= 0; i--) {
if (events[i].Actions.Count == 0) {
events.RemoveAt(i);
}
}
}
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static uint UnserializeChildObjectCount(UndertaleReader reader)
{
Expand Down Expand Up @@ -1717,4 +1736,4 @@ public enum EventSubtypeGesture : uint
/// The global rotate end event.
/// </summary>
GlobalRotateEnd = 76,
}
}
Loading