Skip to content

Fix a null reference exception when PlayerExtraOptionsPanel is null#942

Merged
SadPencil merged 3 commits intoCnCNet:developfrom
BlackgamerzVN:GameLobbyBase-fix
Mar 4, 2026
Merged

Fix a null reference exception when PlayerExtraOptionsPanel is null#942
SadPencil merged 3 commits intoCnCNet:developfrom
BlackgamerzVN:GameLobbyBase-fix

Conversation

@BlackgamerzVN
Copy link
Contributor

Update GameLobbyBase.cs and fixes null crash when PlayerExtraOptionsPanel is null

@BlackgamerzVN BlackgamerzVN marked this pull request as ready for review March 4, 2026 05:50
@SadPencil
Copy link
Member

SadPencil commented Mar 4, 2026

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 PlayerOptionsPanel != null then PlayerExtraOptionsPanel != null always hold (please check)? And therefore making this PR unnecessary

Edit: these lines was introduced in https://github.com/CnCNet/xna-cncnet-client/pull/719/changes#diff-8288b2a427397578c24040412ece4160f93e250af073d4f376042d8b00c525ceR2390

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PlayerExtraOptionsPanel usage in the non-coop (CoopInfo == null) branch of ChangeMap.
  • Changes control flow to return early when PlayerOptionsPanel or PlayerExtraOptionsPanel is null.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2574 to +2577
if (PlayerOptionsPanel == null) return;
if (PlayerExtraOptionsPanel == null) return;
PlayerExtraOptionsPanel.ForcedNoTeamsAllowChecking = true;
PlayerExtraOptionsPanel.UseTeamStartMappingsAllowChecking = true;
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Copy link
Member

@SadPencil SadPencil Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid concern. Need to rethink this PR

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Nightly build for this pull request:

  • artifacts.zip
    This comment is automatic and is meant to allow guests to get latest automatic builds without registering. It is updated on every successful build.

@SadPencil SadPencil requested a review from Copilot March 4, 2026 06:10
@SadPencil SadPencil changed the title Minor fix on PlayerExtraOptionsPanel value returns null Fix a null reference exception when PlayerExtraOptionsPanel is null Mar 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SadPencil SadPencil merged commit 7f123d5 into CnCNet:develop Mar 4, 2026
5 checks passed
@BlackgamerzVN BlackgamerzVN deleted the GameLobbyBase-fix branch March 4, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants