Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous rendering results in random crashes. #38

Open
IceReaper opened this issue Jul 8, 2020 · 1 comment
Open

Continuous rendering results in random crashes. #38

IceReaper opened this issue Jul 8, 2020 · 1 comment

Comments

@IceReaper
Copy link

IceReaper commented Jul 8, 2020

For a live renderer i use the following code:

private class ContinuousGlSurface : GLSurface
{
	private const int FrameDelay = 1000 / 60;

	private readonly Stopwatch stopwatch;

	public Action RenderLoop;

	public ContinuousGlSurface(GraphicsMode graphicsMode, int major, int minor, GraphicsContextFlags graphicsContextFlags)
		: base(graphicsMode, major, minor, graphicsContextFlags)
	{
		this.stopwatch = Stopwatch.StartNew();
	}

	protected override void OnDraw(EventArgs args)
	{
		base.OnDraw(args);

		if (this.stopwatch.ElapsedMilliseconds >= ContinuousGlSurface.FrameDelay)
		{
			this.stopwatch.Restart();
			this.RenderLoop();
		}

		this.Invalidate(false);
	}
}

This works flawless.. basically, because it only works properly with either single buffering (due to frameswap glitches), or not using the stopwatch because not using it will results in rendering as fast as your pc can.
So this works till suddenly out of nowhere a random (sometimes after seconds, sometimes after minutes) crash appears:

OpenTK.Graphics.GraphicsContextException: Failed to make context 65537 current. Error: 2004
   at OpenTK.Platform.Windows.WinGLContext.MakeCurrent(IWindowInfo window)
   at OpenTK.Graphics.GraphicsContext.MakeCurrent(IWindowInfo window)
   at Eto.OpenTK.WinForms.WinGLUserControl.MakeCurrent()
   at Eto.OpenTK.Wpf.WpfWinGLSurfaceHandler.MakeCurrent()
   at Eto.OpenTK.Wpf.WpfWinGLSurfaceHandler.UpdateView()
   at Eto.OpenTK.Wpf.WpfWinGLSurfaceHandler.<AttachEvent>b__7_2(Object sender, PaintEventArgs e)
   at System.Windows.Forms.Control.OnPaint(PaintEventArgs e)
   at Eto.OpenTK.WinForms.WinGLUserControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

When searching for that crash, i came across this one: MonoGame/MonoGame#3196
Which looks quite similar.

@cwensley
Copy link
Member

cwensley commented Oct 2, 2020

hm, weird. Does this happen with the code above (with no GL code), or does it require any GL code to make it happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants