Skip to content

[GEN][ZH] Fix crash upon beacon removal in GameLogic::logicMessageDispatcher #1065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1710,34 +1710,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;
}
}
}
Expand Down
Loading