diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 76a156a..3e883d8 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -393,10 +393,12 @@ namespace DS4Windows as Xbox360OutDevice; //outputDevices[index] = tempXbox; int devIndex = index; - tempXbox.cont.FeedbackReceived += (sender, args) => - { - SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex); - }; + Nefarius.ViGEm.Client.Targets.Xbox360FeedbackReceivedEventHandler p = (sender, args) => + { + SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex); + }; + tempXbox.cont.FeedbackReceived += p; + tempXbox.forceFeedbackCall = p; outputslotMan.DeferredPlugin(tempXbox, index, outputDevices); //tempXbox.Connect(); @@ -411,12 +413,12 @@ namespace DS4Windows as DS4OutDevice; //outputDevices[index] = tempDS4; int devIndex = index; - tempDS4.cont.FeedbackReceived += (sender, args) => - { + Nefarius.ViGEm.Client.Targets.DualShock4FeedbackReceivedEventHandler p = (sender, args) => + { //bool useRumble = false; bool useLight = false; byte largeMotor = args.LargeMotor; - byte smallMotor = args.SmallMotor; - SetDevRumble(device, largeMotor, smallMotor, devIndex); + byte smallMotor = args.SmallMotor; + SetDevRumble(device, largeMotor, smallMotor, devIndex); //DS4Color color = new DS4Color(args.LightbarColor.Red, // args.LightbarColor.Green, // args.LightbarColor.Blue); @@ -468,6 +470,8 @@ namespace DS4Windows //Console.WriteLine(); }; + tempDS4.cont.FeedbackReceived += p; + tempDS4.forceFeedbackCall = p; outputslotMan.DeferredPlugin(tempDS4, index, outputDevices); //tempDS4.Connect(); diff --git a/DS4Windows/DS4Control/DS4OutDevice.cs b/DS4Windows/DS4Control/DS4OutDevice.cs index c477cf7..33cbdb8 100644 --- a/DS4Windows/DS4Control/DS4OutDevice.cs +++ b/DS4Windows/DS4Control/DS4OutDevice.cs @@ -15,6 +15,7 @@ namespace DS4Windows public DualShock4Controller cont; private DualShock4Report report; + public DualShock4FeedbackReceivedEventHandler forceFeedbackCall; public DS4OutDevice(ViGEmClient client) { @@ -141,7 +142,18 @@ namespace DS4Windows } public override void Connect() => cont.Connect(); - public override void Disconnect() => cont.Disconnect(); + public override void Disconnect() + { + if (forceFeedbackCall != null) + { + cont.FeedbackReceived -= forceFeedbackCall; + forceFeedbackCall = null; + } + + cont.Disconnect(); + cont.Dispose(); + cont = null; + } public override string GetDeviceType() => devtype; } } diff --git a/DS4Windows/DS4Control/Xbox360OutDevice.cs b/DS4Windows/DS4Control/Xbox360OutDevice.cs index 5c9d7ba..6313499 100644 --- a/DS4Windows/DS4Control/Xbox360OutDevice.cs +++ b/DS4Windows/DS4Control/Xbox360OutDevice.cs @@ -18,6 +18,7 @@ namespace DS4Windows public Xbox360Controller cont; private Xbox360Report report; + public Xbox360FeedbackReceivedEventHandler forceFeedbackCall; public Xbox360OutDevice(ViGEmClient client) { @@ -137,7 +138,18 @@ namespace DS4Windows } public override void Connect() => cont.Connect(); - public override void Disconnect() => cont.Disconnect(); + public override void Disconnect() + { + if (forceFeedbackCall != null) + { + cont.FeedbackReceived -= forceFeedbackCall; + forceFeedbackCall = null; + } + + cont.Disconnect(); + cont.Dispose(); + cont = null; + } public override string GetDeviceType() => devType; } }