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

'Avalonia.OpenGL.OpenGlException': Unable to make the context current #5562

Closed
afcsoft opened this issue Feb 25, 2021 · 17 comments
Closed

'Avalonia.OpenGL.OpenGlException': Unable to make the context current #5562

afcsoft opened this issue Feb 25, 2021 · 17 comments
Labels

Comments

@afcsoft
Copy link

afcsoft commented Feb 25, 2021

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

  1. Open XamlControlGallery project
  2. Run it
  3. Just wait for crash.

Screenshots
image
image

  • 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)
@afcsoft afcsoft added the bug label Feb 25, 2021
@grokys
Copy link
Member

grokys commented Feb 25, 2021

@kekekeks ☝️

@afcsoft
Copy link
Author

afcsoft commented Feb 25, 2021

Disabling AllowEglInitialization helped a bit. Not crashing about 5 mins. Still same exception.

@llfab
Copy link

llfab commented Jan 14, 2022

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...

@Hanprogramer
Copy link

Still happening. But randomly. I'm not sure what's causing it
image

@jmb10101
Copy link

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.

@kekekeks
Copy link
Member

There are plans to finish and merge #6391 before 11.0. That should be way more stable.

@StipecMV
Copy link

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'

@kekekeks
Copy link
Member

@StipecMV that's a completely different issue. Your glXGetProcAddress has failed for glXCreateContextAttribsARB. Which Linux distro are you using?

@afcsoft
Copy link
Author

afcsoft commented Oct 25, 2022

Any updates?

@Hanprogramer
Copy link

Hanprogramer commented Jan 6, 2023

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

image

@afcsoft
Copy link
Author

afcsoft commented Jan 6, 2023

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

image

"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.

@Hanprogramer
Copy link

Hanprogramer commented Jan 6, 2023

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
image

"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

@afcsoft
Copy link
Author

afcsoft commented Jan 6, 2023

It is just an OpenGL implementation error. And your last statement contradicts with your first statement. Which one is true?

@Hanprogramer
Copy link

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.

@afcsoft
Copy link
Author

afcsoft commented Jan 6, 2023

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.

@Hanprogramer
Copy link

Hanprogramer commented Jan 6, 2023

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);
                }

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 1, 2023

Should be fixed with #9639
Also, UseWGL is not required and not recommended after #9925

@maxkatz6 maxkatz6 closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants