From bba8af6a6346bdc47ae88c8fbe741db7f6546ba5 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 23 Apr 2017 17:48:13 -0700 Subject: [PATCH] Work around a couple of null reference problems that might occur --- DS4Windows/DS4Control/ControlSerivce.cs | 17 ++++++++++--- DS4Windows/DS4Control/DS4StateFieldMapping.cs | 24 +++++++++---------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs index fee5e28..5855ade 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlSerivce.cs @@ -507,8 +507,11 @@ namespace DS4Windows int ind = -1; for (int i = 0, arlength = DS4_CONTROLLER_COUNT; ind == -1 && i < arlength; i++) - if (device == DS4Controllers[i]) + { + DS4Device tempDev = DS4Controllers[i]; + if (tempDev != null && device == tempDev) ind = i; + } if (ind != -1) { @@ -540,11 +543,18 @@ namespace DS4Windows DS4State cState = CurrentState[ind]; device.getPreviousState(PreviousState[ind]); DS4State pState = PreviousState[ind]; + + // Change routine to be more specific to a device. + // Currently updates status of all devices in DS4Form when any battery + // state change occurs. if (pState.Battery != cState.Battery) ControllerStatusChanged(this); + CheckForHotkeys(ind, cState, pState); - if (eastertime) - EasterTime(ind); + + // Temporarily disable easter time routine + //if (eastertime) + // EasterTime(ind); cState = Mapping.SetCurveAndDeadzone(ind, cState); @@ -945,6 +955,7 @@ namespace DS4Windows public bool[] touchreleased = { true, true, true, true }, touchslid = { false, false, false, false }; public byte[] oldtouchvalue = { 0, 0, 0, 0 }; public int[] oldscrollvalue = { 0, 0, 0, 0 }; + protected virtual void CheckForHotkeys(int deviceID, DS4State cState, DS4State pState) { if (!getUseTPforControls(deviceID) && cState.Touch1 && pState.PS) diff --git a/DS4Windows/DS4Control/DS4StateFieldMapping.cs b/DS4Windows/DS4Control/DS4StateFieldMapping.cs index 582b03e..5037cde 100644 --- a/DS4Windows/DS4Control/DS4StateFieldMapping.cs +++ b/DS4Windows/DS4Control/DS4StateFieldMapping.cs @@ -90,10 +90,10 @@ namespace DS4Windows buttons[(int)DS4Controls.DpadDown] = cState.DpadDown; buttons[(int)DS4Controls.DpadLeft] = cState.DpadLeft; - buttons[(int)DS4Controls.TouchLeft] = tp.leftDown; - buttons[(int)DS4Controls.TouchRight] = tp.rightDown; - buttons[(int)DS4Controls.TouchUpper] = tp.upperDown; - buttons[(int)DS4Controls.TouchMulti] = tp.multiDown; + buttons[(int)DS4Controls.TouchLeft] = tp != null ? tp.leftDown : false; + buttons[(int)DS4Controls.TouchRight] = tp != null ? tp.rightDown : false; + buttons[(int)DS4Controls.TouchUpper] = tp != null ? tp.upperDown : false; + buttons[(int)DS4Controls.TouchMulti] = tp != null ? tp.multiDown : false; gryodirs[(int)DS4Controls.GyroXNeg] = exposeState.getGyroX(); gryodirs[(int)DS4Controls.GyroXPos] = exposeState.getGyroX(); @@ -101,15 +101,15 @@ namespace DS4Windows gryodirs[(int)DS4Controls.GyroZPos] = exposeState.getGyroZ(); gryodirs[(int)DS4Controls.GyroZPos] = exposeState.getGyroZ(); - swipedirs[(int)DS4Controls.SwipeLeft] = tp.swipeLeftB; - swipedirs[(int)DS4Controls.SwipeRight] = tp.swipeRightB; - swipedirs[(int)DS4Controls.SwipeUp] = tp.swipeUpB; - swipedirs[(int)DS4Controls.SwipeDown] = tp.swipeDownB; + swipedirs[(int)DS4Controls.SwipeLeft] = tp != null ? tp.swipeLeftB : (byte)0; + swipedirs[(int)DS4Controls.SwipeRight] = tp != null ? tp.swipeRightB : (byte)0; + swipedirs[(int)DS4Controls.SwipeUp] = tp != null ? tp.swipeUpB : (byte)0; + swipedirs[(int)DS4Controls.SwipeDown] = tp != null ? tp.swipeDownB : (byte)0; - swipedirbools[(int)DS4Controls.SwipeLeft] = tp.swipeLeft; - swipedirbools[(int)DS4Controls.SwipeRight] = tp.swipeRight; - swipedirbools[(int)DS4Controls.SwipeUp] = tp.swipeUp; - swipedirbools[(int)DS4Controls.SwipeDown] = tp.swipeDown; + swipedirbools[(int)DS4Controls.SwipeLeft] = tp != null ? tp.swipeLeft : false; + swipedirbools[(int)DS4Controls.SwipeRight] = tp != null ? tp.swipeRight : false; + swipedirbools[(int)DS4Controls.SwipeUp] = tp != null ? tp.swipeUp : false; + swipedirbools[(int)DS4Controls.SwipeDown] = tp != null ? tp.swipeDown : false; } public void populateState(DS4State state)