Skip to content
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

Fix: Crash due to drawRadarBlips calling removeMessage #3662

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,8 @@ void intDisplayWidgets()
{
desiredRadarVisibility = radarVisible();

cleanupOldBeaconMessages();

/* Ensure that any text messages are displayed at bottom of screen */
displayConsoleMessages();
}
Expand Down
35 changes: 0 additions & 35 deletions src/intdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,6 @@ void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV, cons
{
UWORD imageID;
UDWORD delay = 150;
UDWORD i;
SDWORD width, height;
int x = 0, y = 0;
static const uint16_t imagesEnemy[] = {IMAGE_RAD_ENMREAD, IMAGE_RAD_ENM1, IMAGE_RAD_ENM2, IMAGE_RAD_ENM3};
Expand All @@ -1707,40 +1706,6 @@ void drawRadarBlips(int radarX, int radarY, float pixSizeH, float pixSizeV, cons
width = scrollMaxX - scrollMinX;
height = scrollMaxY - scrollMinY;

// Check if it's time to remove beacons
bool removedAMessage = false;
for (i = 0; i < MAX_PLAYERS; i++)
{
/* Go through all the proximity Displays*/
mutating_list_iterate(apsProxDisp[i], [&removedAMessage, i](PROXIMITY_DISPLAY* psProxDisp)
{
if (psProxDisp->psMessage->dataType == MSG_DATA_BEACON)
{
MESSAGE* psCurrMsg = psProxDisp->psMessage;
VIEWDATA* pViewData = psCurrMsg->pViewData;

ASSERT_OR_RETURN(IterationResult::CONTINUE_ITERATION, pViewData != nullptr, "Message without data!");

if (pViewData->type == VIEW_BEACON)
{
ASSERT_OR_RETURN(IterationResult::CONTINUE_ITERATION, pViewData->pData != nullptr, "Help message without data!");
if (pViewData->pData != nullptr && (((VIEW_PROXIMITY*)pViewData->pData)->timeAdded + 60000) <= gameTime)
{
debug(LOG_MSG, "blip timeout for %d, from %d", i, (((VIEW_PROXIMITY*)pViewData->pData)->sender));
removeMessage(psCurrMsg, i); //remove beacon
removedAMessage = true;
return IterationResult::BREAK_ITERATION; //there can only be 1 beacon per player
}
}
}
return IterationResult::CONTINUE_ITERATION;
});
}
if (removedAMessage)
{
jsDebugMessageUpdate();
}

/* Go through all the proximity Displays */
if (selectedPlayer < MAX_PLAYERS)
{
Expand Down
37 changes: 37 additions & 0 deletions src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,3 +840,40 @@ void displayProximityMessage(PROXIMITY_DISPLAY *psProxDisp)
//set the read flag
psProxDisp->psMessage->read = true;
}

void cleanupOldBeaconMessages()
{
// Check if it's time to remove beacons
bool removedAMessage = false;
for (UDWORD i = 0; i < MAX_PLAYERS; i++)
{
/* Go through all the proximity Displays*/
mutating_list_iterate(apsProxDisp[i], [&removedAMessage, i](PROXIMITY_DISPLAY* psProxDisp)
{
if (psProxDisp->psMessage->dataType == MSG_DATA_BEACON)
{
MESSAGE* psCurrMsg = psProxDisp->psMessage;
VIEWDATA* pViewData = psCurrMsg->pViewData;

ASSERT_OR_RETURN(IterationResult::CONTINUE_ITERATION, pViewData != nullptr, "Message without data!");

if (pViewData->type == VIEW_BEACON)
{
ASSERT_OR_RETURN(IterationResult::CONTINUE_ITERATION, pViewData->pData != nullptr, "Help message without data!");
if (pViewData->pData != nullptr && (((VIEW_PROXIMITY*)pViewData->pData)->timeAdded + 60000) <= gameTime)
{
debug(LOG_MSG, "blip timeout for %d, from %d", i, (((VIEW_PROXIMITY*)pViewData->pData)->sender));
removeMessage(psCurrMsg, i); //remove beacon
removedAMessage = true;
return IterationResult::BREAK_ITERATION; //there can only be 1 beacon per player
}
}
}
return IterationResult::CONTINUE_ITERATION;
});
}
if (removedAMessage)
{
jsDebugMessageUpdate();
}
}
2 changes: 2 additions & 0 deletions src/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ void displayProximityMessage(PROXIMITY_DISPLAY *psProxDisp);

bool messageInitVars();

void cleanupOldBeaconMessages();

#endif // __INCLUDED_SRC_MESSAGE_H__
Loading