From 59a67329c728c1291179f91e028f8f4f94da3389 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Wed, 27 May 2020 07:52:53 -0400 Subject: [PATCH] work around crash in clientapi when loading pce nyma --- src/BizHawk.Client.EmuHawk/Api/ClientApi.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs b/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs index 4675abb96e..7219937bbf 100644 --- a/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs +++ b/src/BizHawk.Client.EmuHawk/Api/ClientApi.cs @@ -112,7 +112,8 @@ namespace BizHawk.Client.EmuHawk /// Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information) public static Joypad GetInput(int player) { - if (!1.RangeTo(RunningSystem.MaxControllers).Contains(player)) throw new IndexOutOfRangeException($"{RunningSystem.DisplayName} does not support {player} controller(s)"); + if (!1.RangeTo(RunningSystem.MaxControllers).Contains(player)) + throw new IndexOutOfRangeException($"{RunningSystem.DisplayName} does not support {player} controller(s)"); GetAllInputs(); return _allJoyPads[player - 1]; } @@ -184,9 +185,17 @@ namespace BizHawk.Client.EmuHawk VideoProvider = emu.AsVideoProviderOrDefault(); RomLoaded?.Invoke(null, EventArgs.Empty); - // TODO: Don't crash - // _allJoyPads = new List(RunningSystem.MaxControllers); - // for (var i = 1; i <= RunningSystem.MaxControllers; i++) _allJoyPads.Add(new Joypad(RunningSystem, i)); + try + { + _allJoyPads = new List(RunningSystem.MaxControllers); + for (var i = 1; i <= RunningSystem.MaxControllers; i++) + _allJoyPads.Add(new Joypad(RunningSystem, i)); + } + catch (Exception e) + { + Console.Error.WriteLine("Apihawk is garbage and may not work this session."); + Console.Error.WriteLine(e); + } } ///