From e77ef4de2627b1bbce951832813728e858bb6799 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Fri, 22 Apr 2022 15:53:44 -0300 Subject: [PATCH] Check thread access before executing any Lua function, if thats the case, throw a warning and ignore --- .../BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs index 960a97981..3c5df8cb7 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs @@ -11,6 +11,7 @@ using HarmonyLib; using System.Runtime.CompilerServices; using System.Linq; using System.Reflection; +using System.Threading; [assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.NET_SCRIPT_ASSEMBLY, AllInternalsVisible = true)] [assembly: InternalsVisibleTo(Barotrauma.CsScriptBase.NET_ONE_TIME_SCRIPT_ASSEMBLY, AllInternalsVisible = true)] @@ -301,6 +302,12 @@ namespace Barotrauma } public object CallLuaFunction(object function, params object[] arguments) { + if (Thread.CurrentThread != GameMain.MainThread) + { + PrintMessage($"Warning: Tried to call Lua function outside of the main thread. Arguments = {string.Join(' ', arguments)}, {Environment.StackTrace}"); + return null; + } + try { return lua.Call(function, arguments);