diff --git a/src/Ryujinx.Common/Logging/Logger.cs b/src/Ryujinx.Common/Logging/Logger.cs index 788d2ab3d..6bfa9b1aa 100644 --- a/src/Ryujinx.Common/Logging/Logger.cs +++ b/src/Ryujinx.Common/Logging/Logger.cs @@ -162,6 +162,7 @@ namespace Ryujinx.Common.Logging { if (_logTargets.Any(t => t.Name == target.Name)) { + target.Dispose(); return; } diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs index 66ac31ab4..42a0bd9af 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs @@ -195,11 +195,14 @@ namespace Ryujinx.Graphics.GAL.Multithreading { // The reference table is sized so that it will never overflow, so long as the references are taken after the command is allocated. - int index = _refProducerPtr; + // make sure increment is thread safe + int index = Interlocked.Increment(ref _refProducerPtr) - 1; + + index %= _refQueue.Length; _refQueue[index] = obj; - _refProducerPtr = (_refProducerPtr + 1) % _refQueue.Length; + _refProducerPtr %= _refQueue.Length; return index; } @@ -531,10 +534,15 @@ namespace Ryujinx.Graphics.GAL.Multithreading _running = false; _galWorkAvailable.Set(); - if (_gpuThread != null && _gpuThread.IsAlive) + if (_gpuThread is { IsAlive: true }) { _gpuThread.Join(); } + + if (_backendThread is { IsAlive: true }) + { + _backendThread.Join(); + } // Dispose the renderer. _baseRenderer.Dispose();