From aa807b565dffa608ba9220d1e775b4301f0502e3 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 19 Aug 2022 23:49:51 +0200 Subject: [PATCH] Only run 'Script_Execute()' in main thread --- r5dev/squirrel/sqscript.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/r5dev/squirrel/sqscript.cpp b/r5dev/squirrel/sqscript.cpp index bfdc6ebc..f13fd675 100644 --- a/r5dev/squirrel/sqscript.cpp +++ b/r5dev/squirrel/sqscript.cpp @@ -4,6 +4,7 @@ // //=============================================================================// #include "core/stdafx.h" +#include "tier0/frametask.h" #include "tier1/cvar.h" #include "squirrel/sqapi.h" #include "squirrel/sqinit.h" @@ -246,6 +247,17 @@ SQBool Script_LoadScript(HSQUIRRELVM v, const SQChar* szScriptPath, const SQChar //--------------------------------------------------------------------------------- void Script_Execute(const SQChar* code, SQCONTEXT context) { + if (!ThreadInMainThread()) + { + g_DelayedCallTask->AddFunc([code, context]() + { + string scode(code); + Script_Execute(scode.c_str(), context); + }, 0); + + return; // Only run in main thread. + } + CSquirrelVM* script = Script_GetContextObject(context); if (!script)