From 5c7fd8666a8592b0a0c19a5857d2747c0086ebfc Mon Sep 17 00:00:00 2001 From: Alex Warren Date: Tue, 14 Apr 2026 14:27:15 +0100 Subject: [PATCH] Fix unhandled exceptions in WorldModel crashing the server GetObjectsInScope could return null when RunScript catches a script error and returns null - the foreach in GetExitsListData (and UpdateObjectsList) would then throw NullReferenceException. Return an empty list instead. UpdateLists() was called outside the try-catch in SendCommand, Tick, and RunCallbackAndFinishTurn. Since these all run on threads spawned by DoInNewThreadAndWait, an unhandled exception there crashes the whole process. Moved UpdateLists() inside the existing try-catch in each case. Co-Authored-By: Claude Sonnet 4.6 --- src/Engine/WorldModel.cs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Engine/WorldModel.cs b/src/Engine/WorldModel.cs index acd251381..81ca4462b 100644 --- a/src/Engine/WorldModel.cs +++ b/src/Engine/WorldModel.cs @@ -244,7 +244,7 @@ private QuestList GetObjectsInScope(string scopeFunction) { if (Elements.ContainsKey(ElementType.Function, scopeFunction)) { - return (QuestList)RunProcedure(scopeFunction, true)!; + return (QuestList?)RunProcedure(scopeFunction, true) ?? new QuestList(); } throw new Exception($"No function '{scopeFunction}'"); } @@ -530,17 +530,16 @@ public void SendCommand(string command, int elapsedTime, IDictionary