From 21d65e01e9b98cfafa4b1082abedde4d607d9d44 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 5 Apr 2020 15:22:08 -0500 Subject: [PATCH] Added reference check while unplugging virtual device --- DS4Windows/DS4Control/ControlService.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 5cd031b..2895df5 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -487,15 +487,19 @@ namespace DS4Windows if (!useDInputOnly[index]) { //OutContType contType = Global.OutContType[index]; - string tempType = outputDevices[index].GetDeviceType(); - LogDebug("Unplugging " + tempType + " Controller for input #" + (index + 1), false); OutputDevice dev = outputDevices[index]; - outputDevices[index] = null; - activeOutDevType[index] = OutContType.None; - outputslotMan.DeferredRemoval(dev, index, outputDevices, immediate); - //dev.Disconnect(); - //LogDebug(tempType + " Controller # " + (index + 1) + " unplugged"); - useDInputOnly[index] = true; + if (dev != null) + { + string tempType = dev.GetDeviceType(); + LogDebug("Unplugging " + tempType + " Controller for input #" + (index + 1), false); + + outputDevices[index] = null; + activeOutDevType[index] = OutContType.None; + outputslotMan.DeferredRemoval(dev, index, outputDevices, immediate); + //dev.Disconnect(); + //LogDebug(tempType + " Controller # " + (index + 1) + " unplugged"); + useDInputOnly[index] = true; + } } }