fix(botai): Use cached GUID in destructor to prevent dangling pointer crash
BotAI::~BotAI() was accessing _bot->GetGUID() for blackboard cleanup, but during destruction _bot may be a dangling pointer to already-freed memory. This caused ACCESS_VIOLATION crashes (C0000005) during bot session destruction. The fix uses _cachedBotGuid (captured in constructor) instead, following the same safe pattern already used in UnsubscribeFromEventBuses(). Root cause: Race condition where Player object is destroyed before BotAI destructor completes blackboard cleanup. Evidence from crash logs: - "Removed bot blackboard for Player-1-214CB312020" (hex pointer value) - "AFKSimulator::OnShutdown - Bot AFK simulator shutdown" (empty name) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: luis <[email protected]>
This commit is contained in:
committed by
luis
co-authored by
Claude Opus 4.5
parent
352e74d705
commit
cc9da83744
@@ -329,9 +329,12 @@ BotAI::~BotAI()
|
|||||||
// garbage data, causing std::bad_alloc when string tries huge allocation.
|
// garbage data, causing std::bad_alloc when string tries huge allocation.
|
||||||
|
|
||||||
// Phase 4: Cleanup Shared Blackboard
|
// Phase 4: Cleanup Shared Blackboard
|
||||||
if (_sharedBlackboard && _bot)
|
// CRITICAL FIX: Use _cachedBotGuid instead of _bot->GetGUID()!
|
||||||
|
// During destructor, _bot may be a dangling pointer to already-freed memory.
|
||||||
|
// Using _cachedBotGuid is safe - it was captured in the constructor.
|
||||||
|
if (_sharedBlackboard && !_cachedBotGuid.IsEmpty())
|
||||||
{
|
{
|
||||||
BlackboardManager::RemoveBotBlackboard(_bot->GetGUID());
|
BlackboardManager::RemoveBotBlackboard(_cachedBotGuid);
|
||||||
_sharedBlackboard = nullptr;
|
_sharedBlackboard = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user