From 220953bfe7b0d7e3c3b8f9c2dfb1e21c5113c4c1 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 13 Aug 2017 08:22:18 +0200 Subject: [PATCH] Fixed an issue that prevents further reinitializing if an exception was thrown earlier --- CueSDK.cs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/CueSDK.cs b/CueSDK.cs index c6a1f34..fbb3b5b 100644 --- a/CueSDK.cs +++ b/CueSDK.cs @@ -166,7 +166,7 @@ namespace CUE.NET CorsairError error = LastError; if (error != CorsairError.Success) - Throw(error); + Throw(error, true); if (ProtocolDetails.BreakingChanges) throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" @@ -176,7 +176,7 @@ namespace CUE.NET if (exclusiveAccess) { if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl)) - Throw(LastError); + Throw(LastError, true); HasExclusiveAccess = true; } @@ -216,7 +216,7 @@ namespace CUE.NET error = LastError; if (error != CorsairError.Success) - Throw(error); + Throw(error, true); } InitializedDevices = new ReadOnlyCollection(devices); @@ -252,7 +252,7 @@ namespace CUE.NET CorsairError error = LastError; if (error != CorsairError.Success) - Throw(error); + Throw(error, false); if (ProtocolDetails.BreakingChanges) throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" @@ -261,7 +261,7 @@ namespace CUE.NET if (exclusiveAccess) if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl)) - Throw(LastError); + Throw(LastError, false); HasExclusiveAccess = exclusiveAccess; int deviceCount = _CUESDK.CorsairGetDeviceCount(); @@ -276,7 +276,7 @@ namespace CUE.NET error = LastError; if (error != CorsairError.Success) - Throw(error); + Throw(error, false); } if (KeyboardSDK != null) @@ -299,15 +299,18 @@ namespace CUE.NET IsInitialized = true; } - private static void Throw(CorsairError error) + private static void Throw(CorsairError error, bool reset) { - ProtocolDetails = null; - HasExclusiveAccess = false; - KeyboardSDK = null; - MouseSDK = null; - HeadsetSDK = null; - MousematSDK = null; - IsInitialized = false; + if (reset) + { + ProtocolDetails = null; + HasExclusiveAccess = false; + KeyboardSDK = null; + MouseSDK = null; + HeadsetSDK = null; + MousematSDK = null; + IsInitialized = false; + } throw new CUEException(error); }