Skip to content

Fix #8737: Added Safeguard for Missing Game Options When Saving Older Campaigns#9091

Merged
IllianiBird merged 4 commits into
MegaMek:mainfrom
IllianiBird:gameOptionSaveFix
May 26, 2026
Merged

Fix #8737: Added Safeguard for Missing Game Options When Saving Older Campaigns#9091
IllianiBird merged 4 commits into
MegaMek:mainfrom
IllianiBird:gameOptionSaveFix

Conversation

@IllianiBird
Copy link
Copy Markdown
Collaborator

Fix #8737

Under rare circumstances it seems that a campaign can end up with malformed MegaMek Game Options. null to be precise. This then prevents saving, because the saving process assumes GameOptions has been substantiated.

I've explored the campaign creation process and I cannot find any explanation why campaigns are instantiating with null GameOptions. It shouldn't be possible.

Clearly that isn't the case, so what I've gone ahead and done is added a catch that will self-correct in the event a null GameOption is detected during the save process. The player will be notified when this occurs.

@IllianiBird IllianiBird self-assigned this May 25, 2026
@IllianiBird IllianiBird requested a review from a team as a code owner May 25, 2026 03:38
@IllianiBird IllianiBird added Bug Severity: Critical Issues described as critical as per the new issue form labels May 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 15.23%. Comparing base (9572a8c) to head (0e00370).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
MekHQ/src/mekhq/campaign/Campaign.java 20.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9091      +/-   ##
============================================
+ Coverage     15.19%   15.23%   +0.03%     
- Complexity     9273     9310      +37     
============================================
  Files          1302     1304       +2     
  Lines        172400   172523     +123     
  Branches      26046    26063      +17     
============================================
+ Hits          26204    26281      +77     
- Misses       143151   143198      +47     
+ Partials       3045     3044       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Sleet01
Copy link
Copy Markdown
Collaborator

Sleet01 commented May 25, 2026

From what I recall, we might have seen this when a campaign contained game options that were no longer supported, or when the campaign's options did not contain a value that was now required (due to a recent change in the nightly builds, say).
We'd throw an exception that wouldn't be handled until higher up the call stack than where we set the options instance, and would end up with the default null value.
But I never found the smoking gun.

Copy link
Copy Markdown
Collaborator

@Sleet01 Sleet01 left a comment

Choose a reason for hiding this comment

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

LGTM

@IllianiBird IllianiBird merged commit f906f0f into MegaMek:main May 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Severity: Critical Issues described as critical as per the new issue form

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue] Can't save after moving from MHQ 0.50.06 to MHQ 0.50.11

2 participants