Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(w3ddevice): keep hero radar positions by value, not by pointer

Olcay Seygan3ab31f544861
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
index edc1ec2a0..47125a37c 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
@@ -120,7 +120,10 @@ protected:
Bool m_reconstructViewBox; ///< true when we need to reconstruct the box
ICoord2D m_viewBox[ 4 ]; ///< radar cell points for the 4 corners of view box
- std::list<const Coord3D *> m_cachedHeroPosList; //< cache of hero positions for drawing icons in radar overlay
+ // By value, not by pointer into the object. The list is rebuilt every OVERLAY_REFRESH_RATE
+ // frames and read on every one of them, so a hero killed in between left a pointer into a
+ // deleted Object for the icon pass to read.
+ std::list<Coord3D> m_cachedHeroPosList; //< cache of hero positions for drawing icons in radar overlay
};
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
index f97d7cb1d..06fe3429c 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
@@ -599,10 +599,10 @@ void W3DRadar::drawEvents( Int pixelX, Int pixelY, Int width, Int height )
void W3DRadar::drawIcons( Int pixelX, Int pixelY, Int width, Int height )
{
// draw the hero icons
- std::list<const Coord3D *>::const_iterator iter = m_cachedHeroPosList.begin();
+ std::list<Coord3D>::const_iterator iter = m_cachedHeroPosList.begin();
while (iter != m_cachedHeroPosList.end())
{
- drawHeroIcon( pixelX, pixelY, width, height, (*iter) );
+ drawHeroIcon( pixelX, pixelY, width, height, &(*iter) );
++iter;
}
}
@@ -652,7 +652,7 @@ void W3DRadar::renderObjectList( const RadarObject *listHead, TextureClass *text
// cache hero object positions for drawing in icon layer
if( calcHero && obj->isHero() )
{
- m_cachedHeroPosList.push_back(obj->getPosition());
+ m_cachedHeroPosList.push_back(*obj->getPosition());
}
Bool skip = FALSE;