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
This commit is contained in:
Travis Nickles 2017-04-22 19:46:50 -07:00
parent 8df30a5bbb
commit ade55d3b9f
2 changed files with 5 additions and 2 deletions

View File

@ -397,7 +397,8 @@ namespace DS4Windows
public void StopUpdate() 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)) !ds4Input.ThreadState.HasFlag(System.Threading.ThreadState.AbortRequested))
{ {
try try
@ -418,7 +419,8 @@ namespace DS4Windows
{ {
lock (exitLocker) 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)) !ds4Output.ThreadState.HasFlag(System.Threading.ThreadState.AbortRequested))
{ {
try try

View File

@ -81,6 +81,7 @@ namespace DS4Windows
if (isExclusiveMode && !hDevice.IsOpen) if (isExclusiveMode && !hDevice.IsOpen)
hDevice.OpenDevice(false); hDevice.OpenDevice(false);
} }
if (hDevice.IsOpen) if (hDevice.IsOpen)
{ {
string serial = hDevice.readSerial(); string serial = hDevice.readSerial();