diff --git a/core/EventManager.cpp b/core/EventManager.cpp index eba1a86a..a84b2561 100644 --- a/core/EventManager.cpp +++ b/core/EventManager.cpp @@ -317,6 +317,18 @@ void EventManager::FireEvent(EventInfo *pInfo, int flags, bool bDontBroadcast) m_FreeEvents.push(pInfo); } +void EventManager::CancelCreatedEvent(EventInfo *pInfo) +{ + /* Free event from IGameEventManager2 */ + gameevents->FreeEvent(pInfo->pEvent); + + /* IGameEvent is free at this point, so no one owns this */ + pInfo->pOwner = NULL; + + /* Add EventInfo struct to free event stack */ + m_FreeEvents.push(pInfo); +} + /* IGameEventManager2::FireEvent hook */ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast) { diff --git a/core/EventManager.h b/core/EventManager.h index deb8c5ec..e0ab28da 100644 --- a/core/EventManager.h +++ b/core/EventManager.h @@ -98,6 +98,7 @@ public: EventHookError UnhookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post); EventInfo *CreateEvent(IPluginContext *pContext, const char *name); void FireEvent(EventInfo *pInfo, int flags=0, bool bDontBroadcast=false); + void CancelCreatedEvent(EventInfo *pInfo); private: // IGameEventManager2 hooks bool OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast); bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast); diff --git a/core/smn_events.cpp b/core/smn_events.cpp index 2eb1fb2a..b3cc7508 100644 --- a/core/smn_events.cpp +++ b/core/smn_events.cpp @@ -126,6 +126,8 @@ static cell_t sm_CancelCreatedEvent(IPluginContext *pContext, const cell_t *para return pContext->ThrowNativeError("Game event \"%s\" could not be canceled because it was not created by this plugin", pInfo->pEvent->GetName()); } + g_EventManager.CancelCreatedEvent(pInfo); + /* Free handle on game event */ HandleSecurity sec = {pContext->GetIdentity(), g_pCoreIdent}; g_HandleSys.FreeHandle(hndl, &sec);