Some bug fixes
Changelog: - Reapply some changes that got lost while rebasing from #904 - Make sure to guarantee exclusivity on the GL context (fixing multiple possible race conditions on Windows) - Avoid making GLRenderer disposed multiple time
This commit is contained in:
parent
7b7a462812
commit
d54080c64e
3 changed files with 87 additions and 38 deletions
|
@ -3,6 +3,7 @@ using OpenTK;
|
|||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Input;
|
||||
using OpenTK.Platform;
|
||||
using Ryujinx.Configuration;
|
||||
using Ryujinx.Graphics.OpenGL;
|
||||
using Ryujinx.HLE;
|
||||
|
@ -88,7 +89,9 @@ namespace Ryujinx.Ui
|
|||
|
||||
private void GLRenderer_Initialized(object sender, EventArgs e)
|
||||
{
|
||||
// Release the GL exclusivity that OpenTK gave us.
|
||||
GraphicsContext.MakeCurrent(null);
|
||||
|
||||
WaitEvent.Set();
|
||||
}
|
||||
|
||||
|
@ -168,11 +171,19 @@ namespace Ryujinx.Ui
|
|||
|
||||
public void Exit()
|
||||
{
|
||||
_device.DisposeGpu();
|
||||
if (IsStopped)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsStopped = true;
|
||||
IsActive = false;
|
||||
|
||||
using (ScopedGLContext scopedGLContext = new ScopedGLContext(WindowInfo, GraphicsContext))
|
||||
{
|
||||
_device.DisposeGpu();
|
||||
}
|
||||
|
||||
WaitEvent.Set();
|
||||
}
|
||||
|
||||
|
@ -188,8 +199,10 @@ namespace Ryujinx.Ui
|
|||
|
||||
public void Render()
|
||||
{
|
||||
GraphicsContext.MakeCurrent(WindowInfo);
|
||||
using (ScopedGLContext scopedGLContext = new ScopedGLContext(WindowInfo, GraphicsContext))
|
||||
{
|
||||
_renderer.Initialize();
|
||||
}
|
||||
|
||||
while (IsActive)
|
||||
{
|
||||
|
@ -198,8 +211,8 @@ namespace Ryujinx.Ui
|
|||
return;
|
||||
}
|
||||
|
||||
GraphicsContext.MakeCurrent(WindowInfo);
|
||||
|
||||
using (ScopedGLContext scopedGLContext = new ScopedGLContext(WindowInfo, GraphicsContext))
|
||||
{
|
||||
GL.ClearColor(Color4.Black);
|
||||
|
||||
_ticks += _chrono.ElapsedTicks;
|
||||
|
@ -239,13 +252,13 @@ namespace Ryujinx.Ui
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SwapBuffers()
|
||||
{
|
||||
OpenTK.Graphics.GraphicsContext.CurrentContext.SwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
public void MainLoop()
|
||||
{
|
||||
while (IsActive)
|
||||
|
|
|
@ -433,14 +433,15 @@ namespace Ryujinx.Ui
|
|||
|
||||
DiscordIntegrationModule.SwitchToMainMenu();
|
||||
|
||||
_screenExitStatus.Set();
|
||||
|
||||
Application.Invoke(delegate
|
||||
{
|
||||
_stopEmulation.Sensitive = false;
|
||||
_firmwareInstallFile.Sensitive = true;
|
||||
_firmwareInstallDirectory.Sensitive = true;
|
||||
|
||||
});
|
||||
|
||||
_screenExitStatus.Set();
|
||||
}
|
||||
|
||||
private static void UpdateGameMetadata(string titleId)
|
||||
|
@ -475,7 +476,11 @@ namespace Ryujinx.Ui
|
|||
{
|
||||
UpdateGameMetadata(device.System.TitleIdText);
|
||||
|
||||
_gLWigdet?.Exit();
|
||||
if (_gLWigdet != null)
|
||||
{
|
||||
_gLWigdet.Exit();
|
||||
_screenExitStatus.WaitOne();
|
||||
}
|
||||
}
|
||||
|
||||
Dispose();
|
||||
|
@ -627,15 +632,11 @@ namespace Ryujinx.Ui
|
|||
|
||||
private void Exit_Pressed(object sender, EventArgs args)
|
||||
{
|
||||
_gLWigdet?.Exit();
|
||||
|
||||
End(_emulationContext);
|
||||
}
|
||||
|
||||
private void Window_Close(object sender, DeleteEventArgs args)
|
||||
{
|
||||
_gLWigdet?.Exit();
|
||||
|
||||
End(_emulationContext);
|
||||
}
|
||||
|
||||
|
|
35
Ryujinx/Ui/ScopedGLContext.cs
Normal file
35
Ryujinx/Ui/ScopedGLContext.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using OpenTK.Graphics;
|
||||
using OpenTK.Platform;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Ui
|
||||
{
|
||||
class ScopedGLContext : IDisposable
|
||||
{
|
||||
private IGraphicsContext _graphicsContext;
|
||||
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
public ScopedGLContext(IWindowInfo windowInfo, IGraphicsContext graphicsContext)
|
||||
{
|
||||
_graphicsContext = graphicsContext;
|
||||
|
||||
Monitor.Enter(_lock);
|
||||
|
||||
MakeCurrent(windowInfo);
|
||||
}
|
||||
|
||||
private void MakeCurrent(IWindowInfo windowInfo)
|
||||
{
|
||||
_graphicsContext.MakeCurrent(windowInfo);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
MakeCurrent(null);
|
||||
|
||||
Monitor.Exit(_lock);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue