Don't call sourcepawn detour callbacks from threads other than the main thread
The SourcePawn VM isn't threadsafe.
This commit is contained in:
parent
30fc311738
commit
9d43111829
@ -252,6 +252,10 @@ bool UpdateRegisterArgumentSizes(CHook* pDetour, HookSetup *setup)
|
|||||||
// Central handler for all detours. Heart of the detour support.
|
// Central handler for all detours. Heart of the detour support.
|
||||||
ReturnAction_t HandleDetour(HookType_t hookType, CHook* pDetour)
|
ReturnAction_t HandleDetour(HookType_t hookType, CHook* pDetour)
|
||||||
{
|
{
|
||||||
|
// Can't call into SourcePawn offthread.
|
||||||
|
if (g_MainThreadId != ke::GetCurrentThreadId())
|
||||||
|
return ReturnAction_Ignored;
|
||||||
|
|
||||||
DetourMap *map;
|
DetourMap *map;
|
||||||
if (hookType == HOOKTYPE_PRE)
|
if (hookType == HOOKTYPE_PRE)
|
||||||
map = &g_pPreDetours;
|
map = &g_pPreDetours;
|
||||||
|
@ -15,6 +15,8 @@ HandleType_t g_HookSetupHandle = 0;
|
|||||||
HandleType_t g_HookParamsHandle = 0;
|
HandleType_t g_HookParamsHandle = 0;
|
||||||
HandleType_t g_HookReturnHandle = 0;
|
HandleType_t g_HookReturnHandle = 0;
|
||||||
|
|
||||||
|
ke::ThreadId g_MainThreadId;
|
||||||
|
|
||||||
bool DHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
bool DHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||||
{
|
{
|
||||||
HandleError err;
|
HandleError err;
|
||||||
@ -59,6 +61,7 @@ bool DHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
|||||||
|
|
||||||
g_pEntityListener = new DHooksEntityListener();
|
g_pEntityListener = new DHooksEntityListener();
|
||||||
g_pSignatures = new SignatureGameConfig();
|
g_pSignatures = new SignatureGameConfig();
|
||||||
|
g_MainThreadId = ke::GetCurrentThreadId();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include <IBinTools.h>
|
#include <IBinTools.h>
|
||||||
#include <ISDKTools.h>
|
#include <ISDKTools.h>
|
||||||
#include "sdk-hacks.h"
|
#include "sdk-hacks.h"
|
||||||
|
#include <amtl/am-thread-utils.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sample implementation of the SDK Extension.
|
* @brief Sample implementation of the SDK Extension.
|
||||||
@ -129,4 +130,5 @@ public:
|
|||||||
};
|
};
|
||||||
extern SourceHook::IHookManagerAutoGen *g_pHookManager;
|
extern SourceHook::IHookManagerAutoGen *g_pHookManager;
|
||||||
extern sp_nativeinfo_t g_Natives[];
|
extern sp_nativeinfo_t g_Natives[];
|
||||||
|
extern ke::ThreadId g_MainThreadId;
|
||||||
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user