Guard against ShouldCollide calls from other threads (fixes #2530)
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <sm_platform.h>
|
||||
#include <const.h>
|
||||
#include <IBinTools.h>
|
||||
#include <thread>
|
||||
|
||||
//#define SDKHOOKSDEBUG
|
||||
|
||||
@@ -104,6 +105,7 @@ CGlobalVars *gpGlobals;
|
||||
std::vector<CVTableList *> g_HookList[SDKHook_MAXHOOKS];
|
||||
|
||||
IBinTools *g_pBinTools = NULL;
|
||||
static std::thread::id g_MainThreadId;
|
||||
ICvar *icvar = NULL;
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
@@ -199,6 +201,8 @@ SH_DECL_MANUALHOOK0(CanBeAutobalanced, 0, 0, 0, bool);
|
||||
*/
|
||||
bool SDKHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
{
|
||||
g_MainThreadId = std::this_thread::get_id();
|
||||
|
||||
char buffer[256];
|
||||
g_pSM->BuildPath(Path_SM, buffer, sizeof(buffer)-1, "/extensions/sdkhooks.ext." PLATFORM_LIB_EXT);
|
||||
if (libsys->PathExists(buffer) && libsys->IsPathFile(buffer))
|
||||
@@ -1382,6 +1386,11 @@ void SDKHooks::Hook_SetTransmit(CCheckTransmitInfo *pInfo, bool bAlways)
|
||||
|
||||
bool SDKHooks::Hook_ShouldCollide(int collisionGroup, int contentsMask)
|
||||
{
|
||||
// SourcePawn cannot be called from worker threads. This can happen on some
|
||||
// engine variants, where the engine invokes ShouldCollide off-thread.
|
||||
if (g_MainThreadId != std::this_thread::get_id())
|
||||
RETURN_META_VALUE(MRES_IGNORED, false);
|
||||
|
||||
CBaseEntity *pEntity = META_IFACEPTR(CBaseEntity);
|
||||
|
||||
CVTableHook vhook(pEntity);
|
||||
|
||||
Reference in New Issue
Block a user