Check if the Device is rendering before waiting on it (#86)

Fixes an issue where there were missed references and an ``OperationCancelled`` exception when exiting an application.

Reviewed-on: https://git.ryujinx.app/projects/Ryubing/pulls/86
This commit is contained in:
Max
2026-05-12 02:38:09 +00:00
committed by sh0inx
parent f8167eb625
commit 89ea41ef84
2 changed files with 41 additions and 38 deletions

View File

@@ -177,8 +177,6 @@ namespace Ryujinx.Graphics.Vulkan
} }
} }
// This can somehow become -1.
// Logger.Info?.PrintMsg(LogClass.Gpu, $"_referenceCount: {_referenceCount}");
Debug.Assert(_referenceCount >= 0); Debug.Assert(_referenceCount >= 0);
} }

View File

@@ -622,15 +622,15 @@ namespace Ryujinx.Ava.Systems
// If the GPU has no work and is cancelled, we need to handle that as well. // If the GPU has no work and is cancelled, we need to handle that as well.
WaitHandle.WaitAny(new[] { _gpuDoneEvent, _gpuCancellationTokenSource.Token.WaitHandle }); WaitHandle.WaitAny(new[] { _gpuDoneEvent, _gpuCancellationTokenSource.Token.WaitHandle });
_gpuCancellationTokenSource.Dispose();
// Waiting for work to be finished before we dispose.
if (_renderingStarted) if (_renderingStarted)
{ {
// Waiting for work to be finished before we dispose.
Device.Gpu.WaitUntilGpuReady(); Device.Gpu.WaitUntilGpuReady();
} }
_gpuDoneEvent.Dispose(); _gpuDoneEvent.Dispose();
_gpuCancellationTokenSource.Dispose();
DisposeGpu(); DisposeGpu();
AppExit?.Invoke(this, EventArgs.Empty); AppExit?.Invoke(this, EventArgs.Empty);
@@ -1094,6 +1094,8 @@ namespace Ryujinx.Ava.Systems
_chrono.Start(); _chrono.Start();
Device.Gpu.Renderer.RunLoop(() => Device.Gpu.Renderer.RunLoop(() =>
{
try
{ {
Device.Gpu.SetGpuThread(); Device.Gpu.SetGpuThread();
Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token); Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
@@ -1122,7 +1124,8 @@ namespace Ryujinx.Ava.Systems
InitStatus(); InitStatus();
} }
Device.PresentFrame(() => (RendererHost.EmbeddedWindow as EmbeddedWindowOpenGL)?.SwapBuffers()); Device.PresentFrame(() =>
(RendererHost.EmbeddedWindow as EmbeddedWindowOpenGL)?.SwapBuffers());
} }
if (_ticks >= _ticksPerFrame) if (_ticks >= _ticksPerFrame)
@@ -1130,7 +1133,9 @@ namespace Ryujinx.Ava.Systems
UpdateStatus(); UpdateStatus();
} }
} }
}
finally
{
// Make sure all commands in the run loop are fully executed before leaving the loop. // Make sure all commands in the run loop are fully executed before leaving the loop.
if (Device.Gpu.Renderer is ThreadedRenderer threaded) if (Device.Gpu.Renderer is ThreadedRenderer threaded)
{ {
@@ -1138,8 +1143,8 @@ namespace Ryujinx.Ava.Systems
threaded.FlushThreadedCommands(); threaded.FlushThreadedCommands();
Logger.Info?.PrintMsg(LogClass.Gpu, "Flushed!"); Logger.Info?.PrintMsg(LogClass.Gpu, "Flushed!");
} }
_gpuDoneEvent.Set(); _gpuDoneEvent.Set();
}
}); });
(RendererHost.EmbeddedWindow as EmbeddedWindowOpenGL)?.MakeCurrent(true); (RendererHost.EmbeddedWindow as EmbeddedWindowOpenGL)?.MakeCurrent(true);