Hopefully block edge cases where global `GameInfo` is uninitialised

`Game == null` conditions in `MainForm` ctor looked unreachable, so I changed
them to `Game.IsNullInstance()` which is what I assume was intended, and added
an assert to `RomLoader` in case a bug is introduced later
This commit is contained in:
YoshiRulz 2022-07-26 07:59:57 +10:00
parent d84da4ec4b
commit bd58bde07c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
6 changed files with 20 additions and 25 deletions

View File

@ -703,6 +703,8 @@ namespace BizHawk.Client.Common
return false;
}
_ = game!; // shouldn't be null if `nextEmulator` isn't? just in case
}
catch (Exception ex)
{

View File

@ -198,19 +198,12 @@ namespace BizHawk.Client.Common
movie.SyncSettingsJson = ConfigService.SaveWithType(settable.GetSyncSettings());
}
if (game.IsNullInstance())
{
movie.GameName = "NULL";
}
else
{
movie.GameName = game.FilesystemSafeName();
movie.Hash = game.Hash;
if (game.FirmwareHash != null)
{
movie.FirmwareHash = game.FirmwareHash;
}
}
if (emulator.HasBoardInfo())
{

View File

@ -427,6 +427,7 @@ namespace BizHawk.Client.EmuHawk
private void RecordMovieMenuItem_Click(object sender, EventArgs e)
{
if (Game.IsNullInstance()) return;
if (!Emulator.Attributes().Released)
{
var result = this.ModalMessageBox2(

View File

@ -548,7 +548,7 @@ namespace BizHawk.Client.EmuHawk
var ioa = OpenAdvancedSerializer.ParseWithLegacy(_argParser.cmdRom);
if (ioa is OpenAdvanced_OpenRom oaor) ioa = new OpenAdvanced_OpenRom { Path = oaor.Path.MakeAbsolute() }; // fixes #3224; should this be done for all the IOpenAdvanced types? --yoshi
LoadRom(ioa.SimplePath, new LoadRomArgs { OpenAdvanced = ioa });
if (Game == null)
if (Game.IsNullInstance())
{
ShowMessageBox(owner: null, $"Failed to load {_argParser.cmdRom} specified on commandline");
}
@ -567,7 +567,7 @@ namespace BizHawk.Client.EmuHawk
if (_argParser.cmdMovie != null)
{
_suppressSyncSettingsWarning = true; // We don't want to be nagged if we are attempting to automate
if (Game == null)
if (Game.IsNullInstance())
{
OpenRom();
}
@ -3318,6 +3318,8 @@ namespace BizHawk.Client.EmuHawk
{
if (_currAviWriter != null) return;
if (Game.IsNullInstance()) throw new InvalidOperationException("how is an A/V recording starting with no game loaded? please report this including as much detail as possible");
// select IVideoWriter to use
IVideoWriter aw;
@ -3431,19 +3433,12 @@ namespace BizHawk.Client.EmuHawk
}
else
{
using var sfd = new SaveFileDialog();
if (Game != null)
using SaveFileDialog sfd = new()
{
sfd.FileName = $"{Game.FilesystemSafeName()}.{ext}"; // don't use Path.ChangeExtension, it might wreck game names with dots in them
sfd.InitialDirectory = Config.PathEntries.AvAbsolutePath();
}
else
{
sfd.FileName = "NULL";
sfd.InitialDirectory = Config.PathEntries.AvAbsolutePath();
}
sfd.Filter = new FilesystemFilterSet(new FilesystemFilter(ext, new[] { ext })).ToString();
FileName = $"{Game.FilesystemSafeName()}.{ext}",
Filter = new FilesystemFilterSet(new FilesystemFilter(ext, new[] { ext })).ToString(),
InitialDirectory = Config.PathEntries.AvAbsolutePath(),
};
if (this.ShowDialogWithTempMute(sfd) == DialogResult.Cancel)
{

View File

@ -30,6 +30,8 @@ namespace BizHawk.Client.EmuHawk
IMovieSession movieSession,
FirmwareManager firmwareManager)
{
if (game.IsNullInstance()) throw new InvalidOperationException("how is the traditional Record dialog open with no game loaded? please report this including as much detail as possible");
_mainForm = mainForm;
_config = config;
_game = game;

View File

@ -583,6 +583,8 @@ namespace BizHawk.Client.EmuHawk
return;
}
if (Game.IsNullInstance()) throw new InvalidOperationException("how is TAStudio open with no game loaded? please report this including as much detail as possible");
var filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename
var tasMovie = (ITasMovie)MovieSession.Get(filename);
tasMovie.BindMarkersToInput = Settings.BindMarkersToInput;