Avalonia
Avalonia copied to clipboard
'Avalonia.OpenGL.OpenGlException': Unable to make the context current
Describe the bug
OpenGL rendering controls works just fine but about in 2 minutes, it crashes with this exception:
'Avalonia.OpenGL.OpenGlException': Unable to make the context current
Also, nobody returns my e-mail about paid support request. Hope you guys are okay.
To Reproduce
- Open XamlControlGallery project
- Run it
- Just wait for crash.
Screenshots
- OS: Windows 10 Pro Version: 20H2 Build: 19042.746
- PC:
- CPU: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz 1.80 GHz
- GPU: Intel UHD Graphics 620 , Radeon(TM) 520
- Avalonia Version 0.10.0
Additional context Logs:
[Visual] Exception in render loop: 'Avalonia.OpenGL.OpenGlException: Unable to make the context current
at Avalonia.Win32.OpenGl.WglRestoreContext..ctor(IntPtr gc, IntPtr context, Object monitor, Boolean takeMonitor) in /_/src/Windows/Avalonia.Win32/OpenGl/WglRestoreContext.cs:line 27
at Avalonia.Win32.OpenGl.WglGlPlatformSurface.RenderTarget.BeginDraw() in /_/src/Windows/Avalonia.Win32/OpenGl/WglGlPlatformSurface.cs:line 52
at Avalonia.Skia.GlRenderTarget.BeginRenderingSession() in /_/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs:line 101
at Avalonia.Skia.SkiaGpuRenderTarget.CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer) in /_/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs:line 40
at Avalonia.Rendering.DeferredRenderer.EnsureDrawingContext(IDrawingContextImpl& context) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 599
at Avalonia.Rendering.DeferredRenderer.UpdateRenderLayersAndConsumeSceneIfNeeded(IDrawingContextImpl& context, Boolean recursiveCall) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 397
at Avalonia.Rendering.DeferredRenderer.Render(Boolean forceComposite) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 340
at Avalonia.Rendering.RenderLoop.TimerTick(TimeSpan time) in /_/src/Avalonia.Visuals/Rendering/RenderLoop.cs:line 145' (RenderLoop #53857724)
@kekekeks ☝️
Disabling AllowEglInitialization
helped a bit. Not crashing about 5 mins. Still same exception.
I am getting the very same issue if WGL is enabled even for simpler apps on various Windows 10 and Windows 11 machines.
2022-01-14 00:02:20.037 | Avalonia | TID[ 7] | W:8/32765/32767 C:8/1000/1000 | Error | [Visual] Exception in render loop: 'Avalonia.OpenGL.OpenGlException: Unable to make the context current
at Avalonia.Win32.OpenGl.WglGlPlatformSurface.RenderTarget.BeginDraw() in /_/src/Windows/Avalonia.Win32/OpenGl/WglGlPlatformSurface.cs:line 47
at Avalonia.Skia.GlRenderTarget.BeginRenderingSession() in /_/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs:line 101
at Avalonia.Skia.SkiaGpuRenderTarget.CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer) in /_/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs:line 40
at Avalonia.Rendering.DeferredRenderer.EnsureDrawingContext(IDrawingContextImpl& context) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 618
at Avalonia.Rendering.DeferredRenderer.UpdateRenderLayersAndConsumeSceneIfNeeded(IDrawingContextImpl& context, Boolean recursiveCall) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 416
at Avalonia.Rendering.DeferredRenderer.Render(Boolean forceComposite) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 359
at Avalonia.Rendering.DeferredRenderer.Avalonia.Rendering.IRenderLoopTask.Render() in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 277
at Avalonia.Rendering.RenderLoop.TimerTick(TimeSpan time) in /_/src/Avalonia.Visuals/Rendering/RenderLoop.cs:line 147' (RenderLoop #35236192)
You can see that in TID the thread id is 7, hence, not the UI thread which would be 1.
Maybe this helps...
Still happening. But randomly. I'm not sure what's causing it
Is there any update on this issue or plan on working on it? It is still happening. This should be a very high priority bug as it is essentially a non-starter for any project that wants to use OpenGL within Avalonia on Windows.
There are plans to finish and merge https://github.com/AvaloniaUI/Avalonia/pull/6391 before 11.0. That should be way more stable.
That is strange, I got the same exception on X11
[OpenGL] Unable to initialize GLX-based rendering: 'Avalonia.OpenGL.OpenGlException: Unable to find a suitable GL function for CreateContextAttribsARB
at Avalonia.OpenGL.GlInterfaceBase`1..ctor(Func`2 getProcAddress, TContext context) in /_/src/Avalonia.OpenGL/GlInterfaceBase.cs:line 58
at Avalonia.OpenGL.GlInterfaceBase..ctor(Func`2 getProcAddress) in /_/src/Avalonia.OpenGL/GlInterfaceBase.cs:line 11
at Avalonia.X11.Glx.GlxInterface..ctor() in /_/src/Avalonia.X11/Glx/Glx.cs:line 110
at Avalonia.X11.Glx.GlxDisplay..ctor(X11Info x11, IList`1 probeProfiles) in /_/src/Avalonia.X11/Glx/GlxDisplay.cs:line 20
at Avalonia.X11.Glx.GlxPlatformOpenGlInterface.TryCreate(X11Info x11, IList`1 glProfiles) in /_/src/Avalonia.X11/Glx/GlxPlatformFeature.cs:line 34'
@StipecMV that's a completely different issue. Your glXGetProcAddress
has failed for glXCreateContextAttribsARB
. Which Linux distro are you using?
Any updates?
Still happening, please fix this issue, as this is very disturbing. The issue happens only on NVidia graphics cards. I know this because I was writing my on UI Framework and having the same issue. The best way to handle this is just to add Try/Catch when drawing and handle specifically OpenGlException, then just print the exception instead
Still happening, please fix this issue, as this is very disturbing. The issue happens only on NVidia graphics cards. I know this because I was writing my on UI Framework and having the same issue. The best way to handle this is just to add Try/Catch when drawing and handle specifically OpenGlException
"The issue happens only on Nvidia graphics cards" is incorrect. Intel/AMD/Nvidia does not matter. It throws this exception randomly. It is just an OpenGL implementation error.
Still happening, please fix this issue, as this is very disturbing. The issue happens only on NVidia graphics cards. I know this because I was writing my on UI Framework and having the same issue. The best way to handle this is just to add Try/Catch when drawing and handle specifically OpenGlException
"The issue happens only on Nvidia graphics cards" is incorrect. Intel/AMD/Nvidia does not matter. It throws this exception randomly. It is just an OpenGL implementation error.
What caused the error then? I'm curious. Is it about threading? Edit: if i changed my application settings from the NVidia control panel to "High performance NVidia graphics" which uses the dedicated GPU instead of integrated (by default). The error goes away
Edit2: yeah i forgot i did send a screenshot before from my AMD machine. But still edit1 is something we should think about
It is just an OpenGL implementation error. And your last statement contradicts with your first statement. Which one is true?
I thought it might be from threading. But i checked again without threading turned on on my own UI framework, still the same. Turning on "high performance" mode on nvidia still solves the issue, but we can't expect end users to do this.
I don't think windows or any driver will change to active gpu during the runtime. So that may be true that integrated gpus do have a problem with avalonia's opengl control. But my tests shows the almost opposite. This exception occurs very randomly. That does not mean it won't happen. It is likely to happen anyone that uses avalonia's opengl control in an app. This error will never get a solution from avalonia team, (This is just my guess) It is possible that they can't replicate the issue at all.
I don't think windows or any driver will change to active gpu during the runtime. So that may be true that integrated gpus do have a problem with avalonia's opengl control. But my tests shows the almost opposite. This exception occurs very randomly. That does not mean it won't happen. It is likely to happen anyone that uses avalonia's opengl control in an app. This error will never get a solution from avalonia team, (This is just my guess) It is possible that they can't replicate the issue at all.
Not just Avalonia though, my own UI library also have the same problem. It uses Silk.NET OpenGL for backend and SkiaSharp. Could either be problem with OpenGl and .NET itself. But this is just my guess
EDIT: Using the dedicated graphics device no longer fix my problem. Idk why
EDIT2: Here's how i fixed it on my own ui library:
try
{
SkiaCtx.Flush();
}
catch (Exception e)
{
Console.WriteLine(e);
}
Should be fixed with https://github.com/AvaloniaUI/Avalonia/pull/9639 Also, UseWGL is not required and not recommended after https://github.com/AvaloniaUI/Avalonia/issues/9925