fix(map): Add safety checks to prevent null map crash in AddUpdateObject

Added null pointer validation to:
- WorldObject::AddToObjectUpdate() - validates GetMap() before calling
- WorldObject::RemoveFromObjectUpdate() - same validation
- Map::AddUpdateObject() - validates object pointer
- Map::RemoveUpdateObject() - same validation

These checks prevent potential crashes from memory corruption scenarios
where the Map pointer or object pointer could be invalid.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: luis <[email protected]>
This commit is contained in:
agatho
2026-02-04 20:22:44 -03:00
committed by luis
co-authored by Claude Opus 4.5
parent 5eeaa84d8c
commit 5d09867066
2 changed files with 21 additions and 4 deletions
+16 -2
View File
@@ -3113,13 +3113,27 @@ void WorldObject::BuildUpdate(UpdateDataMapType& data_map)
bool WorldObject::AddToObjectUpdate()
{
GetMap()->AddUpdateObject(this);
// SAFETY CHECK: Validate Map pointer to prevent crash in AddUpdateObject
// Crash at Map.h:573 (hash set insert) could be caused by corrupted Map pointer
Map* map = GetMap();
if (!map)
{
TC_LOG_ERROR("misc", "WorldObject::AddToObjectUpdate called with null map for {}", GetGUID().ToString());
return false;
}
map->AddUpdateObject(this);
return true;
}
void WorldObject::RemoveFromObjectUpdate()
{
GetMap()->RemoveUpdateObject(this);
Map* map = GetMap();
if (!map)
{
TC_LOG_ERROR("misc", "WorldObject::RemoveFromObjectUpdate called with null map for {}", GetGUID().ToString());
return;
}
map->RemoveUpdateObject(this);
}
ObjectGuid WorldObject::GetTransGUID() const
+5 -2
View File
@@ -570,12 +570,15 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void AddUpdateObject(BaseEntity* obj)
{
_updateObjects.insert(obj);
// Null check only - BaseEntity is forward declared, can't call methods here
if (obj)
_updateObjects.insert(obj);
}
void RemoveUpdateObject(BaseEntity* obj)
{
_updateObjects.erase(obj);
if (obj)
_updateObjects.erase(obj);
}
size_t GetActiveNonPlayersCount() const