From 478a0618fbbe855e76e3fc11514df650f24223f7 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 29 Dec 2018 22:10:27 -0600 Subject: [PATCH] Fix exception if ThresholdSlider refreshes when no pads are active. GetFirstActivePadConfig returns a dummy config if nothing is connected, which didn't have any of its arrays created. Fill in dummy arrays for enabledSensors, etc. so refreshes don't throw exceptions if they're updated right when the last controller disconnects. (This is a rare race condition and I've only seen it while stepping in the debugger and disconnecting while stopped.) --- smx-config/Helpers.cs | 2 +- smx-config/SMX.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/smx-config/Helpers.cs b/smx-config/Helpers.cs index 590d52a..b8a7964 100644 --- a/smx-config/Helpers.cs +++ b/smx-config/Helpers.cs @@ -64,7 +64,7 @@ namespace smx_config // There aren't any pads connected. Just return a dummy config, since the UI // isn't visible. - return new SMX.SMXConfig(); + return SMX.SMXConfig.Create(); } public static SMX.SMXConfig GetFirstActivePadConfig() diff --git a/smx-config/SMX.cs b/smx-config/SMX.cs index 42fd1d2..1fd8e4f 100644 --- a/smx-config/SMX.cs +++ b/smx-config/SMX.cs @@ -192,6 +192,19 @@ namespace SMX panelThreshold7High = values[7]; panelThreshold8High = values[8]; } + + // Create an empty SMXConfig. + static public SMXConfig Create() + { + SMXConfig result = new SMXConfig(); + result.enabledSensors = new Byte[5]; + result.stepColor = new Byte[3*9]; + result.individualPanelFSRLow = new UInt16[9]; + result.individualPanelFSRHigh = new UInt16[9]; + result.platformStripColor = new Byte[3]; + + return result; + } }; public struct SMXSensorTestModeData