From 8f4a1f53719499e03d43ecc47126fda1e4b82cf0 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sat, 14 Jun 2025 21:19:19 +0200 Subject: [PATCH 1/4] Added sanity checks on beacon pointer and controlling player. --- .../GameLogic/System/GameLogicDispatch.cpp | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index 7003423f03..652bc8cac5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -1710,34 +1710,37 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it) { Object *beacon = findObjectByID(*it); - if (beacon) + + if (!beacon || !beacon->getControllingPlayer() || !beacon->getControllingPlayer()->getPlayerTemplate()) + { + continue; + } + + const ThingTemplate *thing = TheThingFactory->findTemplate( beacon->getControllingPlayer()->getPlayerTemplate()->getBeaconTemplate() ); + if (thing->isEquivalentTo(beacon->getTemplate())) { - const ThingTemplate *thing = TheThingFactory->findTemplate( beacon->getControllingPlayer()->getPlayerTemplate()->getBeaconTemplate() ); - if (thing->isEquivalentTo(beacon->getTemplate())) + if (beacon->getControllingPlayer() == thisPlayer) { - if (beacon->getControllingPlayer() == thisPlayer) - { - TheGameLogic->destroyObject(beacon); // the owner is telling it to go away. such is life. + TheGameLogic->destroyObject(beacon); // the owner is telling it to go away. such is life. - TheControlBar->markUIDirty(); // check if we should un-grey out the button - } - else if (thisPlayer == ThePlayerList->getLocalPlayer()) + TheControlBar->markUIDirty(); // check if we should un-grey out the button + } + else if (thisPlayer == ThePlayerList->getLocalPlayer()) + { + Drawable *beaconDrawable = beacon->getDrawable(); + if (beaconDrawable) { - Drawable *beaconDrawable = beacon->getDrawable(); - if (beaconDrawable) - { - static NameKeyType nameKeyClientUpdate = NAMEKEY("BeaconClientUpdate"); - ClientUpdateModule ** clientModules = beaconDrawable->getClientUpdateModules(); - if (clientModules) + static NameKeyType nameKeyClientUpdate = NAMEKEY("BeaconClientUpdate"); + ClientUpdateModule ** clientModules = beaconDrawable->getClientUpdateModules(); + if (clientModules) + { + while (*clientModules) { - while (*clientModules) - { - if ((*clientModules)->getModuleNameKey() == nameKeyClientUpdate) - (*(BeaconClientUpdate **)clientModules)->hideBeacon(); + if ((*clientModules)->getModuleNameKey() == nameKeyClientUpdate) + (*(BeaconClientUpdate **)clientModules)->hideBeacon(); - ++clientModules; - } + ++clientModules; } } } From ae1b7b88edd79bb2cbccbe692120f8f0571fe009 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sat, 14 Jun 2025 21:46:00 +0200 Subject: [PATCH 2/4] Refactored to reduce the number of function calls. --- .../GameLogic/System/GameLogicDispatch.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index 652bc8cac5..078077b7c7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -1710,16 +1710,27 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it) { Object *beacon = findObjectByID(*it); + if (!beacon) + { + continue; + } + + Player* controllingPlayer = beacon->getControllingPlayer(); + if (!controllingPlayer) + { + continue; + } - if (!beacon || !beacon->getControllingPlayer() || !beacon->getControllingPlayer()->getPlayerTemplate()) + const PlayerTemplate* playerTemplate = controllingPlayer->getPlayerTemplate(); + if (!playerTemplate) { continue; } - const ThingTemplate *thing = TheThingFactory->findTemplate( beacon->getControllingPlayer()->getPlayerTemplate()->getBeaconTemplate() ); + const ThingTemplate *thing = TheThingFactory->findTemplate( playerTemplate->getBeaconTemplate() ); if (thing->isEquivalentTo(beacon->getTemplate())) { - if (beacon->getControllingPlayer() == thisPlayer) + if (controllingPlayer == thisPlayer) { TheGameLogic->destroyObject(beacon); // the owner is telling it to go away. such is life. From 9f143deea29c8a72ff7c33bbb021a189687c9a7a Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sat, 14 Jun 2025 22:13:03 +0200 Subject: [PATCH 3/4] Changed pointers. --- .../GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index 078077b7c7..1b73b064d2 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -1715,13 +1715,13 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) continue; } - Player* controllingPlayer = beacon->getControllingPlayer(); + Player *controllingPlayer = beacon->getControllingPlayer(); if (!controllingPlayer) { continue; } - const PlayerTemplate* playerTemplate = controllingPlayer->getPlayerTemplate(); + const PlayerTemplate *playerTemplate = controllingPlayer->getPlayerTemplate(); if (!playerTemplate) { continue; From b3e45c4d6971396b88e6342cf70b419d9d3992b7 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Sat, 14 Jun 2025 22:14:44 +0200 Subject: [PATCH 4/4] Replicated changes in General. --- .../GameLogic/System/GameLogicDispatch.cpp | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index cf835cb373..a3c03e2f6b 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -1682,34 +1682,48 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it) { Object *beacon = findObjectByID(*it); - if (beacon) + if (!beacon) + { + continue; + } + + Player *controllingPlayer = beacon->getControllingPlayer(); + if (!controllingPlayer) + { + continue; + } + + const PlayerTemplate *playerTemplate = controllingPlayer->getPlayerTemplate(); + if (!playerTemplate) + { + continue; + } + + const ThingTemplate *thing = TheThingFactory->findTemplate( playerTemplate->getBeaconTemplate() ); + if (thing->isEquivalentTo(beacon->getTemplate())) { - const ThingTemplate *thing = TheThingFactory->findTemplate( beacon->getControllingPlayer()->getPlayerTemplate()->getBeaconTemplate() ); - if (thing->isEquivalentTo(beacon->getTemplate())) + if (controllingPlayer == thisPlayer) { - if (beacon->getControllingPlayer() == thisPlayer) - { - TheGameLogic->destroyObject(beacon); // the owner is telling it to go away. such is life. + TheGameLogic->destroyObject(beacon); // the owner is telling it to go away. such is life. - TheControlBar->markUIDirty(); // check if we should un-grey out the button - } - else if (thisPlayer == ThePlayerList->getLocalPlayer()) + TheControlBar->markUIDirty(); // check if we should un-grey out the button + } + else if (thisPlayer == ThePlayerList->getLocalPlayer()) + { + Drawable *beaconDrawable = beacon->getDrawable(); + if (beaconDrawable) { - Drawable *beaconDrawable = beacon->getDrawable(); - if (beaconDrawable) - { - static NameKeyType nameKeyClientUpdate = NAMEKEY("BeaconClientUpdate"); - ClientUpdateModule ** clientModules = beaconDrawable->getClientUpdateModules(); - if (clientModules) + static NameKeyType nameKeyClientUpdate = NAMEKEY("BeaconClientUpdate"); + ClientUpdateModule ** clientModules = beaconDrawable->getClientUpdateModules(); + if (clientModules) + { + while (*clientModules) { - while (*clientModules) - { - if ((*clientModules)->getModuleNameKey() == nameKeyClientUpdate) - (*(BeaconClientUpdate **)clientModules)->hideBeacon(); + if ((*clientModules)->getModuleNameKey() == nameKeyClientUpdate) + (*(BeaconClientUpdate **)clientModules)->hideBeacon(); - ++clientModules; - } + ++clientModules; } } }