diff options
author | frosch <frosch@openttd.org> | 2009-01-24 21:38:30 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-01-24 21:38:30 +0000 |
commit | 512cc98b35891a491b4e24a0a5f440f8b9e548d7 (patch) | |
tree | c0ed0b1bddf1dd2a265a49e9750fa96b02fd9ee5 /src/ai | |
parent | 9b73303b4d4c91cb0fcee44679e5443bc8c5fa0b (diff) | |
download | openttd-512cc98b35891a491b4e24a0a5f440f8b9e548d7.tar.xz |
(svn r15262) -Fix: AIEvents were not freed, when they were not queued for any AI.
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/ai_core.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index 04a759d47..60475f24b 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -160,28 +160,47 @@ /* static */ void AI::NewEvent(CompanyID company, AIEvent *event) { + /* AddRef() and Release() need to be called at least once, so do it here */ + event->AddRef(); + /* Clients should ignore events */ - if (_networking && !_network_server) return; + if (_networking && !_network_server) { + event->Release(); + return; + } /* Only AIs can have an event-queue */ - if (!IsValidCompanyID(company) || IsHumanCompany(company)) return; + if (!IsValidCompanyID(company) || IsHumanCompany(company)) { + event->Release(); + return; + } /* Queue the event */ CompanyID old_company = _current_company; _current_company = company; AIEventController::InsertEvent(event); _current_company = old_company; + + event->Release(); } /* static */ void AI::BroadcastNewEvent(AIEvent *event, CompanyID skip_company) { + /* AddRef() and Release() need to be called at least once, so do it here */ + event->AddRef(); + /* Clients should ignore events */ - if (_networking && !_network_server) return; + if (_networking && !_network_server) { + event->Release(); + return; + } /* Try to send the event to all AIs */ for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { if (c != skip_company) AI::NewEvent(c, event); } + + event->Release(); } void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2) |