diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index 951ad0c525..358ab4f834 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -242,18 +242,15 @@ /* static */ void AI::NewEvent(CompanyID company, ScriptEvent *event) { - /* AddRef() and Release() need to be called at least once, so do it here */ - event->AddRef(); + ScriptObjectRef counter(event); /* Clients should ignore events */ if (_networking && !_network_server) { - event->Release(); return; } /* Only AIs can have an event-queue */ if (!Company::IsValidAiID(company)) { - event->Release(); return; } @@ -261,18 +258,14 @@ Backup cur_company(_current_company, company); Company::Get(_current_company)->ai_instance->InsertEvent(event); cur_company.Restore(); - - event->Release(); } /* static */ void AI::BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company) { - /* AddRef() and Release() need to be called at least once, so do it here */ - event->AddRef(); + ScriptObjectRef counter(event); /* Clients should ignore events */ if (_networking && !_network_server) { - event->Release(); return; } @@ -280,8 +273,6 @@ for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { if (c != skip_company) AI::NewEvent(c, event); } - - event->Release(); } /* static */ void AI::Save(CompanyID company) diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index a5cdb2575b..de1edf37ec 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -145,18 +145,15 @@ /* static */ void Game::NewEvent(ScriptEvent *event) { - /* AddRef() and Release() need to be called at least once, so do it here */ - event->AddRef(); + ScriptObjectRef counter(event); /* Clients should ignore events */ if (_networking && !_network_server) { - event->Release(); return; } /* Check if Game instance is alive */ if (Game::instance == nullptr) { - event->Release(); return; } @@ -164,8 +161,6 @@ Backup cur_company(_current_company, OWNER_DEITY); Game::instance->InsertEvent(event); cur_company.Restore(); - - event->Release(); } /* static */ void Game::ResetConfig()