Fix a null reference exception when PlayerExtraOptionsPanel is null#942
Fix a null reference exception when PlayerExtraOptionsPanel is null#942SadPencil merged 3 commits intoCnCNet:developfrom
Conversation
|
Ah wait. if (PlayerOptionsPanel != null)
{
PlayerExtraOptionsPanel.ForcedNoTeamsAllowChecking = false;
PlayerExtraOptionsPanel.ForcedNoTeams = false;
PlayerExtraOptionsPanel.UseTeamStartMappingsAllowChecking = false;
PlayerExtraOptionsPanel.UseTeamStartMappings = false;
}We also have these lines. This probably means if Edit: these lines was introduced in https://github.com/CnCNet/xna-cncnet-client/pull/719/changes#diff-8288b2a427397578c24040412ece4160f93e250af073d4f376042d8b00c525ceR2390 |
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent a null-reference crash in GameLobbyBase.ChangeMap when PlayerExtraOptionsPanel is not available while updating map/game-mode–dependent option state.
Changes:
- Adds null guards around
PlayerExtraOptionsPanelusage in the non-coop (CoopInfo == null) branch ofChangeMap. - Changes control flow to return early when
PlayerOptionsPanelorPlayerExtraOptionsPanelis null.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (PlayerOptionsPanel == null) return; | ||
| if (PlayerExtraOptionsPanel == null) return; | ||
| PlayerExtraOptionsPanel.ForcedNoTeamsAllowChecking = true; | ||
| PlayerExtraOptionsPanel.UseTeamStartMappingsAllowChecking = true; |
There was a problem hiding this comment.
The new early return statements can exit ChangeMap after disableGameOptionUpdateBroadcast was set to true (line 2445), which means it never gets reset to false (line 2585) and also skips OnGameOptionChanged(), MapPreviewBox updates, and CopyPlayerDataToUI(). Instead of returning, keep the method flow and only guard the PlayerExtraOptionsPanel property assignments (e.g., wrap them in a null-check / use null-conditional), or ensure disableGameOptionUpdateBroadcast is always reset via try/finally. Also, the PlayerOptionsPanel null-check here is unrelated to the dereference that was crashing (it’s PlayerExtraOptionsPanel).
There was a problem hiding this comment.
Valid concern. Need to rethink this PR
|
Nightly build for this pull request:
|
This reverts commit 0c68c05.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Update GameLobbyBase.cs and fixes null crash when PlayerExtraOptionsPanel is null