fix(logic): Add nullptr check to thisPlayer in GameLogic::logicMessageDispatcher#2383
fix(logic): Add nullptr check to thisPlayer in GameLogic::logicMessageDispatcher#2383Caball009 wants to merge 5 commits intoTheSuperHackers:mainfrom
Conversation
|
on 645 we have I wonder if this needs clarifying that I am guessing that |
I have a PR planned for this one which makes the change that player = thisPlayer, which seemed to pass 1k replays, but wanted to test that a bit more |
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | Adds an upfront nullptr guard for thisPlayer with an early return, then removes now-redundant per-case null checks across MSG_CREATE_SELECTED_GROUP, MSG_REMOVE_FROM_SELECTED_GROUP, MSG_DESTROY_SELECTED_GROUP, MSG_CREATE_TEAM*, MSG_SELECT_TEAM*, MSG_ADD_TEAM*, and MSG_PURCHASE_SCIENCE. Also replaces scattered msg->getPlayerIndex() calls with thisPlayer->getPlayerIndex() for consistency. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[logicMessageDispatcher called] --> B[Resolve thisPlayer via\nThePlayerList->getNthPlayer]
B --> C{thisPlayer == nullptr?}
C -- Yes --> D[DEBUG_CRASH + early return]
C -- No --> E[Setup currentlySelectedGroup\nif in-game network msg]
E --> F[Switch on msgType]
F --> G[MSG_CREATE_SELECTED_GROUP\nuses thisPlayer->getPlayerMask]
F --> H[MSG_REMOVE_FROM_SELECTED_GROUP\nuses thisPlayer->getPlayerMask]
F --> I[MSG_DESTROY_SELECTED_GROUP\nsetCurrentlySelectedAIGroup]
F --> J[MSG_CREATE/SELECT/ADD_TEAM*\nuses thisPlayer directly]
F --> K[MSG_LOGIC_CRC\ncached via thisPlayer->getPlayerIndex]
F --> L[MSG_PURCHASE_SCIENCE\nsanity: SCIENCE_INVALID only]
F --> M[... other cases ...]
Last reviewed commit: 7c8b814
xezon
left a comment
There was a problem hiding this comment.
Nice cleanup. But there is CRC mismatch risk.
Also there are 2 more msg->getPlayerIndex() in commented and compiled out code.
| for (; i<ThePlayerList->getPlayerCount(); ++i) | ||
| { | ||
| if (i != msg->getPlayerIndex()) | ||
| if (i != thisPlayer->getPlayerIndex()) |
There was a problem hiding this comment.
Instead of doing thisPlayer->getPlayerIndex() you could also add a const int playerIndex = msg->getPlayerIndex() at the begin of the function and then use that.
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Show resolved
Hide resolved
xezon
left a comment
There was a problem hiding this comment.
Very hot. Needs replication in Generals.
This PR changes the
nullptrassertion onthisPlayerinGameLogic::logicMessageDispatcherto an early return. Although there are a couple of places in this function that check explicitly for it, a lot of code assumes that this pointer is not null, so it makes sense to check that up front.Commit 1 adds the check.
Commit 2 removes code that's become redundant (implicitly).
Commit 3 changes
msg->getPlayerIndextothisPlayer->getPlayerIndexfor the sole purpose of consistency with code that already uses the latter.TODO: