diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 868acea..e78a6a6 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -163,7 +163,6 @@ namespace DS4Windows public event EventHandler Removal = null; public event EventHandler SyncChange = null; public event EventHandler SerialChange = null; - //public event EventHandler PublishRemoval = null; public HidDevice HidDevice => hDevice; public bool IsExclusive => HidDevice.IsExclusive; @@ -579,25 +578,20 @@ namespace DS4Windows int lastError = 0; while (!exitOutputThread) { - bool result = false; + bool result = false, currentRumble = false; - if (outputRumble) + if (currentRumble) { - lock (outputReportBuffer) - { - outputReportBuffer.CopyTo(outputReport, 0); - outputPendCount--; - outputRumble = false; - } - lock(outputReport) { result = writeOutput(); } + currentRumble = false; if (!result) { - outputRumble = true; + currentRumble = true; + exitOutputThread = true; int thisError = Marshal.GetLastWin32Error(); if (lastError != thisError) { @@ -608,11 +602,18 @@ namespace DS4Windows } } - if (!outputRumble) + if (!currentRumble) { lastError = 0; lock (outputReportBuffer) + { Monitor.Wait(outputReportBuffer); + outputReportBuffer.CopyTo(outputReport, 0); + outputPendCount--; + outputRumble = false; + } + + currentRumble = true; } } }