Check thread access before executing any Lua function, if thats the case, throw a warning and ignore

This commit is contained in:
Evil Factory
2022-04-22 15:53:44 -03:00
parent fd0c3ba19d
commit e77ef4de26

View File

@@ -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);