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 2 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 |
|---|---|
| Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | Replaces the debug-only assert on thisPlayer with a proper early return guard (with DEBUG_CRASH), renames thisPlayer → msgPlayer throughout, removes now-redundant local null checks in MSG_CREATE_SELECTED_GROUP / MSG_REMOVE_FROM_SELECTED_GROUP, and replaces one msg->getPlayerIndex() call with msgPlayer->getPlayerIndex() for consistency. All call-sites updated correctly. |
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | Mirrors the Generals changes exactly: early-return null guard, thisPlayer → msgPlayer rename, removal of redundant local null checks, and msg->getPlayerIndex() → msgPlayer->getPlayerIndex() consistency fix. Zero Hour specific code (e.g. MSG_ENABLE_RETALIATION_MODE RETAIL_COMPATIBLE_CRC branch) also correctly updated. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[logicMessageDispatcher called] --> B{msg != nullptr?}
B -- "No (debug assert)" --> Z[Crash / UB in release]
B -- Yes --> C["msgPlayer = ThePlayerList->getNthPlayer(msg->getPlayerIndex())"]
C --> D{msgPlayer == nullptr?}
D -- Yes --> E[DEBUG_CRASH + return early]
D -- No --> F[Build currentlySelectedGroup\nfrom msgPlayer's selection]
F --> G[Process switch msgType]
G --> H["MSG_NEW_GAME / MSG_CLEAR_GAME_DATA\n(game state - does not use msgPlayer)"]
G --> I["Object-command cases\n(use msgPlayer for ownership checks)"]
G --> J["MSG_CREATE_SELECTED_GROUP /\nMSG_REMOVE_FROM_SELECTED_GROUP\n(redundant null check removed)"]
G --> K["MSG_PURCHASE_SCIENCE\n(redundant thisPlayer == nullptr check removed)"]
G --> L["MSG_LOGIC_CRC\n(msgPlayer->getPlayerIndex() instead of msg->getPlayerIndex())"]
Last reviewed commit: "Added nullptr check ..."
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.
|
Renamed
@xezon The diff is not as clean as I'd like it to be. If you like I can redo the commits and split the changes into four commits:
|
38c2e7d to
9445212
Compare
Can do. I suggest make the renaming for both games first. Then the null test fixes for both games. |
93207d9 to
faee6a5
Compare
|
Cleaned up the commits; no changes in the code. Ready to be merged. |
|
Can you make it 2 commits that can be Merged with Rebase into main? |
Just to be sure, you want me to combine commits 1 & 2 and 3 & 4? |
faee6a5 to
41d07eb
Compare
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.TODO:
thisPlayertomsgPlayer.