From b8a104af07c24bc9a458bfcc76c04669617ed7cb Mon Sep 17 00:00:00 2001 From: Causeless Date: Mon, 22 Jan 2024 09:49:37 +0000 Subject: [PATCH 1/3] Fix crash from Lua GC during ConsoleMan script update --- Source/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Main.cpp b/Source/Main.cpp index f2ddb59555..f8d9cfdb17 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -329,6 +329,7 @@ void RunGameLoop() { g_FrameMan.Update(); g_LuaMan.Update(); + g_ConsoleMan.Update(); g_ActivityMan.Update(); if (g_SceneMan.GetScene()) { @@ -347,7 +348,6 @@ void RunGameLoop() { // It's in this spot to allow it to be set by UInputMan update and ConsoleMan update, and read from ActivityMan update. g_PresetMan.ClearReloadEntityPresetCalledThisUpdate(); - g_ConsoleMan.Update(); g_PerformanceMan.StopPerformanceMeasurement(PerformanceMan::SimTotal); if (!g_ActivityMan.IsInActivity()) { From 9c12bc15d1860019fe3cd2249c232acec5233fa4 Mon Sep 17 00:00:00 2001 From: Causeless Date: Mon, 22 Jan 2024 09:51:32 +0000 Subject: [PATCH 2/3] More accurate update order in case scripts are reloaded via UInputMan --- Source/Main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Main.cpp b/Source/Main.cpp index f8d9cfdb17..31629b1457 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -319,7 +319,10 @@ void RunGameLoop() { g_PerformanceMan.StartPerformanceMeasurement(PerformanceMan::SimTotal); + g_LuaMan.Update(); + g_UInputMan.Update(); + g_ConsoleMan.Update(); // It is vital that server is updated after input manager but before activity because input manager will clear received pressed and released events on next update. if (g_NetworkServer.IsServerModeEnabled()) { @@ -328,8 +331,7 @@ void RunGameLoop() { } g_FrameMan.Update(); - g_LuaMan.Update(); - g_ConsoleMan.Update(); + g_ActivityMan.Update(); if (g_SceneMan.GetScene()) { From 7ee1d59fa1ca4e4d6ddefaf9275672cd3f00c921 Mon Sep 17 00:00:00 2001 From: Causeless Date: Mon, 22 Jan 2024 09:54:35 +0000 Subject: [PATCH 3/3] Fixed segfault on reloading objects without a preset --- Source/Entities/MovableObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Entities/MovableObject.cpp b/Source/Entities/MovableObject.cpp index c64fb84326..0833fd3065 100644 --- a/Source/Entities/MovableObject.cpp +++ b/Source/Entities/MovableObject.cpp @@ -563,7 +563,7 @@ int MovableObject::ReloadScripts() { // TODO consider getting rid of this const_cast. It would require either code duplication or creating some non-const methods (specifically of PresetMan::GetEntityPreset, which may be unsafe. Could be this gross exceptional handling is the best way to go. MovableObject* movableObjectPreset = const_cast(dynamic_cast(g_PresetMan.GetEntityPreset(GetClassName(), GetPresetName(), GetModuleID()))); - if (this != movableObjectPreset) { + if (movableObjectPreset && this != movableObjectPreset) { movableObjectPreset->ReloadScripts(); }