forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 167
fix(logic): Add nullptr check to thisPlayer in GameLogic::logicMessageDispatcher #2383
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
Caball009
wants to merge
5
commits into
TheSuperHackers:main
Choose a base branch
from
Caball009:fix_thisPlayer_logicMessageDispatcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+16
−54
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ce76b15
Added check on 'thisPlayer'.
Caball009 03918d2
Removed redundant player pointer checks.
Caball009 c0d0f24
Changed 'msg->getPlayerIndex' to 'thisPlayer->getPlayerIndex'.
Caball009 108f3c9
Merge branch 'main' into fix_thisPlayer_logicMessageDispatcher
Caball009 7c8b814
Removed two more instances of 'msg->getPlayerIndex'.
Caball009 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -350,8 +350,11 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| #endif | ||
|
|
||
| Player *thisPlayer = ThePlayerList->getNthPlayer( msg->getPlayerIndex() ); | ||
| DEBUG_ASSERTCRASH( thisPlayer, ("logicMessageDispatcher: Processing message from unknown player (player index '%d')", | ||
| msg->getPlayerIndex()) ); | ||
| if (thisPlayer == nullptr) | ||
| { | ||
| DEBUG_CRASH(("logicMessageDispatcher: Processing message from unknown player (player index '%d')", msg->getPlayerIndex())); | ||
| return; | ||
| } | ||
|
|
||
| AIGroupPtr currentlySelectedGroup = nullptr; | ||
|
|
||
|
|
@@ -407,7 +410,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| if (commandName.isNotEmpty() /*&& msg->getType() != GameMessage::MSG_FRAME_TICK*/) | ||
| { | ||
| DEBUG_LOG(("Frame %d: GameLogic::logicMessageDispatcher() saw a %s from player %d (%ls)", getFrame(), commandName.str(), | ||
| msg->getPlayerIndex(), thisPlayer->getPlayerDisplayName().str())); | ||
| thisPlayer->getPlayerIndex(), thisPlayer->getPlayerDisplayName().str())); | ||
| } | ||
| #endif | ||
| #endif // DEBUG_LOGGING | ||
|
|
@@ -1583,13 +1586,6 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| case GameMessage::MSG_CREATE_SELECTED_GROUP: | ||
| { | ||
| Bool createNewGroup = msg->getArgument( 0 )->boolean; | ||
| Player *player = ThePlayerList->getNthPlayer(msg->getPlayerIndex()); | ||
|
|
||
| if (player == nullptr) { | ||
| DEBUG_CRASH(("GameLogicDispatch - MSG_CREATE_SELECTED_GROUP had an invalid player number")); | ||
| break; | ||
| } | ||
|
|
||
| Bool firstObject = TRUE; | ||
|
|
||
| for (Int i = 1; i < msg->getArgumentCount(); ++i) { | ||
|
|
@@ -1598,7 +1594,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| continue; | ||
| } | ||
|
|
||
| selectObject(obj, createNewGroup && firstObject, player->getPlayerMask()); | ||
| selectObject(obj, createNewGroup && firstObject, thisPlayer->getPlayerMask()); | ||
| firstObject = FALSE; | ||
| } | ||
|
|
||
|
|
@@ -1609,21 +1605,14 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| //--------------------------------------------------------------------------------------------- | ||
| case GameMessage::MSG_REMOVE_FROM_SELECTED_GROUP: | ||
| { | ||
| Player *player = ThePlayerList->getNthPlayer(msg->getPlayerIndex()); | ||
|
|
||
| if (player == nullptr) { | ||
| DEBUG_CRASH(("GameLogicDispatch - MSG_CREATE_SELECTED_GROUP had an invalid player number")); | ||
| break; | ||
| } | ||
|
|
||
| for (Int i = 0; i < msg->getArgumentCount(); ++i) { | ||
| ObjectID objID = msg->getArgument(i)->objectID; | ||
| Object *objToRemove = findObjectByID(objID); | ||
| if (!objToRemove) { | ||
| continue; | ||
| } | ||
|
|
||
| deselectObject(objToRemove, player->getPlayerMask()); | ||
| deselectObject(objToRemove, thisPlayer->getPlayerMask()); | ||
| } | ||
|
|
||
| break; | ||
|
|
@@ -1633,11 +1622,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| //--------------------------------------------------------------------------------------------- | ||
| case GameMessage::MSG_DESTROY_SELECTED_GROUP: | ||
| { | ||
| Player *player = ThePlayerList->getNthPlayer(msg->getPlayerIndex()); | ||
| if (player != nullptr) | ||
| { | ||
| player->setCurrentlySelectedAIGroup(nullptr); | ||
| } | ||
| thisPlayer->setCurrentlySelectedAIGroup(nullptr); | ||
|
|
||
| break; | ||
|
|
||
|
|
@@ -1851,7 +1836,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| Int i=0; | ||
| for (; i<ThePlayerList->getPlayerCount(); ++i) | ||
| { | ||
| if (i != msg->getPlayerIndex()) | ||
| if (i != thisPlayer->getPlayerIndex()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing |
||
| { | ||
| Player *otherPlayer = ThePlayerList->getNthPlayer(i); | ||
| if (thisPlayer->getRelationship(otherPlayer->getDefaultTeam()) == ALLIES && | ||
|
|
@@ -1933,13 +1918,9 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| case GameMessage::MSG_CREATE_TEAM8: | ||
| case GameMessage::MSG_CREATE_TEAM9: | ||
| { | ||
| Int playerIndex = msg->getPlayerIndex(); | ||
| Player *player = ThePlayerList->getNthPlayer(playerIndex); | ||
| DEBUG_ASSERTCRASH(player != nullptr, ("Could not find player for create team message")); | ||
|
|
||
| // TheSuperHackers @tweak Stubbjax 17/08/2025 The local player processes this message in CommandXlat for immediate assignment. | ||
| if (player && !player->isLocalPlayer()) | ||
| player->processCreateTeamGameMessage(msg->getType() - GameMessage::MSG_CREATE_TEAM0, msg); | ||
| if (!thisPlayer->isLocalPlayer()) | ||
| thisPlayer->processCreateTeamGameMessage(msg->getType() - GameMessage::MSG_CREATE_TEAM0, msg); | ||
|
|
||
| break; | ||
| } | ||
|
|
@@ -1955,16 +1936,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| case GameMessage::MSG_SELECT_TEAM8: | ||
| case GameMessage::MSG_SELECT_TEAM9: | ||
| { | ||
| Int playerIndex = msg->getPlayerIndex(); | ||
| Player *player = ThePlayerList->getNthPlayer(playerIndex); | ||
| DEBUG_ASSERTCRASH(player != nullptr, ("Could not find player for select team message")); | ||
|
|
||
| if (player == nullptr) | ||
| { | ||
| break; | ||
| } | ||
|
|
||
| player->processSelectTeamGameMessage(msg->getType() - GameMessage::MSG_SELECT_TEAM0, msg); | ||
| thisPlayer->processSelectTeamGameMessage(msg->getType() - GameMessage::MSG_SELECT_TEAM0, msg); | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -1979,16 +1951,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| case GameMessage::MSG_ADD_TEAM8: | ||
| case GameMessage::MSG_ADD_TEAM9: | ||
| { | ||
| Int playerIndex = msg->getPlayerIndex(); | ||
| Player *player = ThePlayerList->getNthPlayer(playerIndex); | ||
| DEBUG_ASSERTCRASH(player != nullptr, ("Could not find player for add team message")); | ||
|
|
||
| if (player == nullptr) | ||
| { | ||
| break; | ||
| } | ||
|
|
||
| player->processAddTeamGameMessage(msg->getType() - GameMessage::MSG_ADD_TEAM0, msg); | ||
| thisPlayer->processAddTeamGameMessage(msg->getType() - GameMessage::MSG_ADD_TEAM0, msg); | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -2024,11 +1987,10 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| #endif | ||
| } | ||
|
|
||
| //UnsignedInt oldCRC = m_cachedCRCs[msg->getPlayerIndex()]; | ||
| UnsignedInt newCRC = msg->getArgument(0)->integer; | ||
| //DEBUG_LOG(("Received CRC of %8.8X from %ls on frame %d", newCRC, | ||
| //thisPlayer->getPlayerDisplayName().str(), m_frame)); | ||
| m_cachedCRCs[msg->getPlayerIndex()] = newCRC; // to mask problem: = (oldCRC < newCRC)?newCRC:oldCRC; | ||
| m_cachedCRCs[thisPlayer->getPlayerIndex()] = newCRC; | ||
| } | ||
| else if (TheRecorder && TheRecorder->isPlaybackMode()) | ||
| { | ||
|
|
@@ -2048,7 +2010,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) | |
| ScienceType science = (ScienceType)msg->getArgument( 0 )->integer; | ||
|
|
||
| // sanity | ||
| if( science == SCIENCE_INVALID || thisPlayer == nullptr ) | ||
| if( science == SCIENCE_INVALID ) | ||
| break; | ||
|
|
||
| thisPlayer->attemptToPurchaseScience(science); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.