Browse Source

Added SleepLoopRenderTimer because of libnvidia-glcore.so crashes

pull/4424/head
Nikita Tsukanov 6 years ago
parent
commit
475fea4d1d
  1. 33
      src/Avalonia.Visuals/Rendering/SleepLoopRenderTimer.cs
  2. 2
      src/Avalonia.X11/X11Platform.cs

33
src/Avalonia.Visuals/Rendering/SleepLoopRenderTimer.cs

@ -0,0 +1,33 @@
using System;
using System.Diagnostics;
using System.Threading;
namespace Avalonia.Rendering
{
public class SleepLoopRenderTimer : IRenderTimer
{
public event Action<TimeSpan> Tick;
public SleepLoopRenderTimer(int fps)
{
var timeBetweenTicks = TimeSpan.FromSeconds(1d / fps);
new Thread(() =>
{
var st = Stopwatch.StartNew();
var now = st.Elapsed;
var lastTick = now;
while (true)
{
var timeTillNextTick = lastTick + timeBetweenTicks - now;
if (timeTillNextTick.TotalMilliseconds > 1)
Thread.Sleep(timeTillNextTick);
Tick?.Invoke(now);
now = st.Elapsed;
}
}) { IsBackground = true }.Start();
}
}
}

2
src/Avalonia.X11/X11Platform.cs

@ -47,7 +47,7 @@ namespace Avalonia.X11
AvaloniaLocator.CurrentMutable.BindToSelf(this)
.Bind<IWindowingPlatform>().ToConstant(this)
.Bind<IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this))
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
.Bind<IRenderTimer>().ToConstant(new SleepLoopRenderTimer(60))
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control))
.Bind<IKeyboardDevice>().ToFunc(() => KeyboardDevice)

Loading…
Cancel
Save