From 8304e8b00aa451ef7eace8abd446cac0e842de4e Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Wed, 15 Oct 2025 21:59:04 +0000 Subject: [PATCH] SpecialPowerModule: Add null checks for SpecialPowerTemplate before accessing its members --- .../Object/SpecialPower/SpecialPowerModule.cpp | 11 +++++++---- .../Object/SpecialPower/SpecialPowerModule.cpp | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp index 4d164ee5775..88aea4cf0d4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp @@ -110,7 +110,7 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa { //A sharedNSync special only startPowerRecharges when first scienced or when executed, //Since a new modue with same SPTemplates may construct at any time. - if ( getSpecialPowerTemplate()->isSharedNSync() == FALSE ) + if ( getSpecialPowerTemplate() && getSpecialPowerTemplate()->isSharedNSync() == FALSE ) startPowerRecharge(); } // WE USED TO DO THE POLL-EVERYBODY-AND-VOTE-ON-WHO-TO-SYNC-TO THING HERE, @@ -127,7 +127,8 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa // but there is already a science granted for our shared superweapon, // lets make sure TheIngameUI knows about our public timer // add this weapon to the UI if it has a public timer for all to see - if( m_pausedCount == 0 && + if( getSpecialPowerTemplate() && + m_pausedCount == 0 && getSpecialPowerTemplate()->isSharedNSync() == TRUE && getSpecialPowerTemplate()->hasPublicTimer() == TRUE && getObject()->getControllingPlayer() && @@ -153,7 +154,8 @@ const AudioEventRTS& SpecialPowerModule::getInitiateSound() const SpecialPowerModule::~SpecialPowerModule() { - if( getSpecialPowerModuleData()->m_specialPowerTemplate->hasPublicTimer() == TRUE && + if( getSpecialPowerModuleData()->m_specialPowerTemplate && + getSpecialPowerModuleData()->m_specialPowerTemplate->hasPublicTimer() == TRUE && getObject()->getControllingPlayer() ) TheInGameUI->removeSuperweapon( getObject()->getControllingPlayer()->getPlayerIndex(), getPowerName(), @@ -727,7 +729,8 @@ void SpecialPowerModule::loadPostProcess( void ) // but there is already a science granted for our shared superweapon, // lets make sure TheIngameUI knows about our public timer // add this weapon to the UI if it has a public timer for all to see - if( m_pausedCount == 0 && + if( getSpecialPowerTemplate() && + m_pausedCount == 0 && getSpecialPowerTemplate()->isSharedNSync() == TRUE && getSpecialPowerTemplate()->hasPublicTimer() == TRUE && getObject()->getControllingPlayer() && diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp index e5213921df3..a59da57df7a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp @@ -112,7 +112,7 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa { //A sharedNSync special only startPowerRecharges when first scienced or when executed, //Since a new modue with same SPTemplates may construct at any time. - if ( getSpecialPowerTemplate()->isSharedNSync() == FALSE ) + if ( getSpecialPowerTemplate() && getSpecialPowerTemplate()->isSharedNSync() == FALSE ) startPowerRecharge(); } // WE USED TO DO THE POLL-EVERYBODY-AND-VOTE-ON-WHO-TO-SYNC-TO THING HERE, @@ -129,7 +129,8 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa // but there is already a science granted for our shared superweapon, // lets make sure TheIngameUI knows about our public timer // add this weapon to the UI if it has a public timer for all to see - if( m_pausedCount == 0 && + if( getSpecialPowerTemplate() && + m_pausedCount == 0 && getSpecialPowerTemplate()->isSharedNSync() == TRUE && getSpecialPowerTemplate()->hasPublicTimer() == TRUE && getObject()->getControllingPlayer() && @@ -155,7 +156,8 @@ const AudioEventRTS& SpecialPowerModule::getInitiateSound() const SpecialPowerModule::~SpecialPowerModule() { - if( getSpecialPowerModuleData()->m_specialPowerTemplate->hasPublicTimer() == TRUE && + if( getSpecialPowerModuleData()->m_specialPowerTemplate && + getSpecialPowerModuleData()->m_specialPowerTemplate->hasPublicTimer() == TRUE && getObject()->getControllingPlayer() ) TheInGameUI->removeSuperweapon( getObject()->getControllingPlayer()->getPlayerIndex(), getPowerName(), @@ -871,7 +873,8 @@ void SpecialPowerModule::loadPostProcess( void ) // but there is already a science granted for our shared superweapon, // lets make sure TheIngameUI knows about our public timer // add this weapon to the UI if it has a public timer for all to see - if( m_pausedCount == 0 && + if( getSpecialPowerTemplate() && + m_pausedCount == 0 && getSpecialPowerTemplate()->isSharedNSync() == TRUE && getSpecialPowerTemplate()->hasPublicTimer() == TRUE && getObject()->getControllingPlayer() &&