Fix macOS builds.

This commit is contained in:
Pieter-Jan Briers
2021-05-02 21:48:14 +02:00
parent 6005208285
commit 0c9e322b3e

View File

@@ -1,4 +1,5 @@
using System.Threading.Channels;
using System.Runtime.InteropServices;
using System.Threading.Channels;
using System.Threading.Tasks;
using OpenToolkit.GraphicsLibraryFramework;
using Robust.Shared;
@@ -12,6 +13,11 @@ namespace Robust.Client.Graphics.Clyde
{
private sealed partial class GlfwWindowingImpl
{
// glfwPostEmptyEvent is broken on macOS and crashes when not called from the main thread
// (despite what the docs claim, and yes this makes it useless).
// Because of this, we just forego it and use glfwWaitEventsTimeout on macOS instead.
private static readonly bool IsMacOS = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
private bool _windowingRunning;
private ChannelWriter<CmdBase> _cmdWriter = default!;
private ChannelReader<CmdBase> _cmdReader = default!;
@@ -47,7 +53,10 @@ namespace Robust.Client.Graphics.Clyde
while (_windowingRunning)
{
GLFW.WaitEvents();
if (IsMacOS)
GLFW.WaitEventsTimeout(0.008);
else
GLFW.WaitEvents();
while (_cmdReader.TryRead(out var cmd))
{
@@ -148,7 +157,8 @@ namespace Robust.Client.Graphics.Clyde
_cmdWriter.TryWrite(cmd);
// Post empty event to unstuck WaitEvents if necessary.
GLFW.PostEmptyEvent();
if (!IsMacOS)
GLFW.PostEmptyEvent();
}
private void SendEvent(EventBase ev)