From ade55d3b9f2977171026df8957dd5aa6567b0288 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 22 Apr 2017 19:46:50 -0700 Subject: [PATCH] Change methods to check for null thread objects It looks like there are cases when the stop update methods could be called before the thread objecs are created --- DS4Windows/DS4Library/DS4Device.cs | 6 ++++-- DS4Windows/DS4Library/DS4Devices.cs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index a2ff7c7..93b365b 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -397,7 +397,8 @@ namespace DS4Windows public void StopUpdate() { - if (ds4Input.IsAlive && !ds4Input.ThreadState.HasFlag(System.Threading.ThreadState.Stopped) && + if (ds4Input != null && + ds4Input.IsAlive && !ds4Input.ThreadState.HasFlag(System.Threading.ThreadState.Stopped) && !ds4Input.ThreadState.HasFlag(System.Threading.ThreadState.AbortRequested)) { try @@ -418,7 +419,8 @@ namespace DS4Windows { lock (exitLocker) { - if (ds4Output.IsAlive && !ds4Output.ThreadState.HasFlag(System.Threading.ThreadState.Stopped) && + if (ds4Output != null && + ds4Output.IsAlive && !ds4Output.ThreadState.HasFlag(System.Threading.ThreadState.Stopped) && !ds4Output.ThreadState.HasFlag(System.Threading.ThreadState.AbortRequested)) { try diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index 58f8877..fbd2b8d 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -81,6 +81,7 @@ namespace DS4Windows if (isExclusiveMode && !hDevice.IsOpen) hDevice.OpenDevice(false); } + if (hDevice.IsOpen) { string serial = hDevice.readSerial();