Skip to content

Commit 8f59fd5

Browse files
committed
fix: prevent early global cleanup when inside invoke
closes #501
1 parent cbeac50 commit 8f59fd5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

managed/CounterStrikeSharp.API/Core/ScriptContext.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public unsafe ScriptContext(fxScriptContext* context)
8383

8484
internal fxScriptContext m_extContext = new fxScriptContext();
8585

86+
internal bool isCleanupLocked = false;
87+
8688
[SecuritySafeCritical]
8789
public void Reset()
8890
{
@@ -101,8 +103,16 @@ private void InternalReset()
101103
[SecuritySafeCritical]
102104
public void Invoke()
103105
{
104-
InvokeNativeInternal();
105-
GlobalCleanUp();
106+
if (!isCleanupLocked)
107+
{
108+
isCleanupLocked = true;
109+
InvokeNativeInternal();
110+
GlobalCleanUp();
111+
isCleanupLocked = false;
112+
return;
113+
}
114+
115+
InvokeNativeInternal();
106116
}
107117

108118
[SecurityCritical]

0 commit comments

Comments
 (0)