Skip to content

Commit ffe9f5e

Browse files
committed
bugfix(ThingFactory): Reset ThingTemplate ID for each match to avoid mismatches after playing custom maps.
1 parent b878990 commit ffe9f5e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

GeneralsMD/Code/GameEngine/Include/Common/ThingFactory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class ThingFactory : public SubsystemInterface
124124

125125
ThingTemplate *m_firstTemplate; ///< head of linked list
126126
UnsignedShort m_nextTemplateID; ///< next available ID for templates
127+
UnsignedShort m_templateCount; ///< the value of m_nextTemplateID before loading the first map (even shellmap)
127128

128129
ThingTemplateHashMap m_templateHashMap; ///< all thing templates, for fast lookup.
129130

GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ThingFactory::ThingFactory()
105105
{
106106
m_firstTemplate = NULL;
107107
m_nextTemplateID = 1; // not zero!
108+
m_templateCount = 0;
108109

109110
#ifdef USING_STLPORT
110111
m_templateHashMap.resize( TEMPLATE_HASH_SIZE );
@@ -207,6 +208,8 @@ void ThingFactory::init( void )
207208
//-------------------------------------------------------------------------------------------------
208209
void ThingFactory::reset( void )
209210
{
211+
UnsignedInt erased = 0;
212+
210213
ThingTemplate *t;
211214
// go through all templates and delete any overrides
212215
for( t = m_firstTemplate; t; /* empty */ )
@@ -234,10 +237,15 @@ void ThingFactory::reset( void )
234237
if (stillValid == NULL) {
235238
// Also needs to be removed from the Hash map.
236239
m_templateHashMap.erase(templateName);
240+
++erased;
237241
}
238242

239243
t = nextT;
240244
}
245+
246+
// TheSuperHackers @bugfix Caball009 25/12/2025 Avoid mismatches by making m_nextTemplateID unique for a single match instead of unique since game launch.
247+
DEBUG_ASSERTCRASH(m_templateIDCount + erased == m_nextTemplateID, ("Thing template ID is invalid after deleting overrides"));
248+
m_nextTemplateID = m_templateCount;
241249
}
242250

243251
//-------------------------------------------------------------------------------------------------
@@ -542,6 +550,8 @@ void ThingFactory::postProcessLoad()
542550

543551
}
544552

553+
m_templateCount = m_nextTemplateID;
554+
545555
#ifdef CHECK_THING_NAMES
546556
dumpMissingStringNames();
547557
exit(0);

0 commit comments

Comments
 (0)