fix(savegame): Use getFinalOverride in WeaponSet xfer load to match Object constructor#2160
fix(savegame): Use getFinalOverride in WeaponSet xfer load to match Object constructor#2160bobtista wants to merge 2 commits into
Conversation
| const WeaponTemplateSet* set = obj->getTemplate()->findWeaponTemplateSet(obj->getWeaponSetFlags()); | ||
| DEBUG_ASSERTCRASH(set, ("findWeaponSet should never return null")); | ||
| if (set && set != m_curWeaponTemplateSet) | ||
| // TheSuperHackers @bugfix bobtista 20/01/2026 After checkpoint load, the m_curWeaponTemplateSet pointer |
There was a problem hiding this comment.
My first hunch here is that this change is a hack. Why is m_curWeaponTemplateSet set to something that satisfies the weapon flags but is not actually the real deal? It indicates that the issue is higher up.
There was a problem hiding this comment.
Ok, updated with a better approach.
When an Object is created (Object.cpp:230):
tt = (const ThingTemplate*)tt->getFinalOverride();
The Object uses the final override of the template.
But when WeaponSet::xfer(LOAD) restored weapon data (WeaponSet.cpp:231):
const ThingTemplate* tt = TheThingFactory->findTemplate(ttName);
m_curWeaponTemplateSet = tt->findWeaponTemplateSet(wsFlags);
It used findTemplate() which returns the base template, not the final override.
The fix is to just add t = (const ThingTemplate*)tt->getFinalOverride(); to WeaponSet::xfer(LOAD):
|
Looks like a good change, but the title and issue description need to be updated (the summary is no longer in line with the current code change). |
Updated |
d182d6a to
536d22f
Compare
|
Rebased again, this is ready for re-review |
Summary
Fixes weapon timing state corruption after loading a saved game by ensuring WeaponSet uses the same template override as Object.
Notes
Objectconstructor callsgetFinalOverride()on the template (Object.cpp:230)WeaponSet::xfer(LOAD)was usingTheThingFactory->findTemplate()which returns the base template, not the final overridem_curWeaponTemplateSetto point to a different ThingTemplate's weapon sets thanobj->getTemplate()updateWeaponSet()triggered unnecessary weapon reallocation, resetting timing stateFix
Add
getFinalOverride()call inWeaponSet::xfer(LOAD)to match what Object does, ensuring consistent template pointers.Testing
Todo