Skip to content

Commit

Permalink
writeMessageFile: Fix crash if proximity display not found for message
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 20, 2024
1 parent b90c249 commit fa9134d
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7696,36 +7696,42 @@ static bool writeMessageFile(const char *pFileName)
{
return psProx->psMessage == psMessage; //compare the pointers
});
ASSERT(psProxIt != apsProxDisp[player].end(), "Save message; proximity display not found for message");
PROXIMITY_DISPLAY* psProx = *psProxIt;
if (psProx && psProx->type == POS_PROXDATA)
if (psProxIt != apsProxDisp[player].end())
{
//message has viewdata so store the name
VIEWDATA *pViewData = psMessage->pViewData;
ini.setValue("name", pViewData->name);
PROXIMITY_DISPLAY* psProx = *psProxIt;
if (psProx && psProx->type == POS_PROXDATA)
{
//message has viewdata so store the name
VIEWDATA *pViewData = psMessage->pViewData;
ini.setValue("name", pViewData->name);

// save beacon data
if (psMessage->dataType == MSG_DATA_BEACON)
// save beacon data
if (psMessage->dataType == MSG_DATA_BEACON)
{
VIEW_PROXIMITY *viewData = (VIEW_PROXIMITY *)psMessage->pViewData->pData;
ini.setVector2i("position", Vector2i(viewData->x, viewData->y));
ini.setValue("sender", viewData->sender);
}
}
else
{
VIEW_PROXIMITY *viewData = (VIEW_PROXIMITY *)psMessage->pViewData->pData;
ini.setVector2i("position", Vector2i(viewData->x, viewData->y));
ini.setValue("sender", viewData->sender);
// message has object so store Object Id
const BASE_OBJECT *psObj = psMessage->psObj;
if (psObj)
{
ini.setValue("obj/id", psObj->id);
ini.setValue("obj/player", psObj->player);
ini.setValue("obj/type", psObj->type);
}
else
{
ASSERT(false, "Message type has no object data to save ?");
}
}
}
else
{
// message has object so store Object Id
const BASE_OBJECT *psObj = psMessage->psObj;
if (psObj)
{
ini.setValue("obj/id", psObj->id);
ini.setValue("obj/player", psObj->player);
ini.setValue("obj/type", psObj->type);
}
else
{
ASSERT(false, "Message type has no object data to save ?");
}
ASSERT(psProxIt != apsProxDisp[player].end(), "Save message; proximity display not found for message");
}
}
else
Expand Down

0 comments on commit fa9134d

Please sign in to comment.