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

OpenGlException: eglMakeCurrent failed with error EGL_CONTEXT_LOST #4128

Closed
adirh3 opened this issue Jun 15, 2020 · 14 comments · Fixed by #9639
Closed

OpenGlException: eglMakeCurrent failed with error EGL_CONTEXT_LOST #4128

adirh3 opened this issue Jun 15, 2020 · 14 comments · Fixed by #9639
Labels
Milestone

Comments

@adirh3
Copy link
Contributor

adirh3 commented Jun 15, 2020

This happens to me when using the version on the master, it's very rare but happened 3 times when I logged into my computer and opened the window using the Show functions.
AllowEglInitialization=true and UseDeferredRendering = false

Application: Blast.exe CoreCLR Version: 5.0.20.27801 .NET Version: 5.0.0-preview.5.20278.1 Description: The process was terminated due to an unhandled exception. Exception Info: Avalonia.OpenGL.OpenGlException: eglMakeCurrent failed with error EGL_CONTEXT_LOST (0x300E) at Avalonia.OpenGL.EglContext.MakeCurrent(EglSurface surface) at Avalonia.OpenGL.EglGlPlatformSurface.RenderTarget.BeginDraw() at Avalonia.Skia.GlRenderTarget.BeginRenderingSession() at Avalonia.Skia.SkiaGpuRenderTarget.CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer) at Avalonia.Rendering.ImmediateRenderer.Paint(Rect rect) at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) This happens to me when I use Acrylic + UseGPU randomly, couldn't find any issue like this, are you familiar with it or I should open an issue?

@capdj
Copy link
Contributor

capdj commented Jun 24, 2020

Just confirming I saw this same error too today - while resizing a window which had opened and displayed fine previously.

@kekekeks kekekeks added the bug label Jun 24, 2020
@kekekeks kekekeks added this to the 0.10 milestone Jun 24, 2020
@adirh3
Copy link
Contributor Author

adirh3 commented Jul 1, 2020

image
Update - This happened twice before crashing on the same exception

@kekekeks
Copy link
Member

Please, try with this PR #4242

@adirh3
Copy link
Contributor Author

adirh3 commented Jul 10, 2020

Please, try with this PR #4242

I will try and update if it works, thanks.

@adirh3
Copy link
Contributor Author

adirh3 commented Jul 13, 2020

@kekekeks Didn't happen for me since I started using the latest nightly build but I also switched to the deferred renderer (not sure if it matters). Also, it's probably worth noting that this exception occurred to me only when logging to a computer through RDP.

@capdj
Copy link
Contributor

capdj commented Jul 13, 2020

Just to confirm, I've seen it happen 2-3 times running on a normal session, not via RDP so (assuming mine is the same issue) it's not confined just to RDP sessions.

@kekekeks
Copy link
Member

The thing is, there are two scenarios when EGL_CONTEXT_LOST can happen:

  1. a genuine device loss (a switch to RDP session with RemoteFX, hardware device reset, etc)
  2. an invalid command issued by Avalonia

The first one we need to handle properly, but for second one we need to determine what was causing it, since invalid calls might cause worse errors as well.

@adirh3
Copy link
Contributor Author

adirh3 commented Jul 13, 2020

The thing is, there are two scenarios when EGL_CONTEXT_LOST can happen:

  1. a genuine device loss (a switch to RDP session with RemoteFX, hardware device reset, etc)
  2. an invalid command issued by Avalonia

The first one we need to handle properly, but for second one we need to determine what was causing it, since invalid calls might cause worse errors as well.

It used to happen because of RDP but just now it happened when I was just opening the window and it has different stack trace -
Exception Info: Avalonia.OpenGL.OpenGlException: eglCreateWindowSurface failed with error EGL_CONTEXT_LOST (0x300E) at Avalonia.OpenGL.EglDisplay.CreateWindowSurface(IntPtr window) at Avalonia.OpenGL.EglGlPlatformSurface.CreateGlRenderTarget() at Avalonia.Skia.GlSkiaGpu.TryCreateRenderTarget(IEnumerable1 surfaces)
at Avalonia.Skia.PlatformRenderInterface.CreateRenderTarget(IEnumerable1 surfaces) at Avalonia.Controls.TopLevel.CreateRenderTarget() at Avalonia.Controls.TopLevel.Avalonia.Rendering.IRenderRoot.CreateRenderTarget() at Avalonia.Rendering.DeferredRenderer.EnsureDrawingContext(IDrawingContextImpl& context) at Avalonia.Rendering.DeferredRenderer.UpdateRenderLayersAndConsumeSceneIfNeeded(IDrawingContextImpl& context, Boolean recursiveCall) at Avalonia.Rendering.DeferredRenderer.Render(Boolean forceComposite) at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)

Also, if it helps - I noticed one of the exceptions had different error code -
Exception Info: Avalonia.OpenGL.OpenGlException: eglCreateWindowSurface failed with error EGL_BAD_ALLOC (0x3003) at Avalonia.OpenGL.EglDisplay.CreateWindowSurface(IntPtr window) at Avalonia.OpenGL.EglGlPlatformSurface.CreateGlRenderTarget() at Avalonia.Skia.GlSkiaGpu.TryCreateRenderTarget(IEnumerable1 surfaces)
at Avalonia.Skia.PlatformRenderInterface.CreateRenderTarget(IEnumerable1 surfaces) at Avalonia.Controls.TopLevel.CreateRenderTarget() at Avalonia.Controls.TopLevel.Avalonia.Rendering.IRenderRoot.CreateRenderTarget() at Avalonia.Rendering.ImmediateRenderer.Paint(Rect rect) at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam

@PathogenDavid
Copy link
Contributor

I encountered this today while upgrading my graphics drivers for AvaloniaUI/XamlControlsGallery#4 while XamlControlGallery was running.

Probably not all that useful, but here's the exception and stack trace:

Click to expand

Avalonia.OpenGL.OpenGlException: 'eglCreateWindowSurface failed with error EGL_CONTEXT_LOST (0x300E)'

 	Avalonia.OpenGL.dll!Avalonia.OpenGL.EglDisplay.CreateWindowSurface(System.IntPtr window)	Unknown
 	Avalonia.OpenGL.dll!Avalonia.OpenGL.EglGlPlatformSurface.CreateGlRenderTarget()	Unknown
 	Avalonia.Skia.dll!Avalonia.Skia.GlRenderTarget.GlRenderTarget(SkiaSharp.GRContext grContext, Avalonia.OpenGL.IGlPlatformSurface glSurface)	Unknown
 	Avalonia.Skia.dll!Avalonia.Skia.GlSkiaGpu.TryCreateRenderTarget(System.Collections.Generic.IEnumerable<object> surfaces)	Unknown
 	Avalonia.Skia.dll!Avalonia.Skia.PlatformRenderInterface.CreateRenderTarget(System.Collections.Generic.IEnumerable<object> surfaces)	Unknown
 	Avalonia.Controls.dll!Avalonia.Controls.TopLevel.CreateRenderTarget()	Unknown
 	Avalonia.Controls.dll!Avalonia.Controls.TopLevel.Avalonia.Rendering.IRenderRoot.CreateRenderTarget()	Unknown
 	Avalonia.Visuals.dll!Avalonia.Rendering.DeferredRenderer.EnsureDrawingContext(ref Avalonia.Platform.IDrawingContextImpl context)	Unknown
 	Avalonia.Visuals.dll!Avalonia.Rendering.DeferredRenderer.UpdateRenderLayersAndConsumeSceneIfNeeded(ref Avalonia.Platform.IDrawingContextImpl context, bool recursiveCall)	Unknown
 	Avalonia.Visuals.dll!Avalonia.Rendering.DeferredRenderer.Render(bool forceComposite)	Unknown
 	Avalonia.Visuals.dll!Avalonia.Rendering.DeferredRenderer.Paint(Avalonia.Rect rect)	Unknown
 	Avalonia.Controls.dll!Avalonia.Controls.TopLevel.HandlePaint(Avalonia.Rect rect)	Unknown
 	Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.AppWndProc(System.IntPtr hWnd, uint msg, System.IntPtr wParam, System.IntPtr lParam)	Unknown
 	Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.WndProc(System.IntPtr hWnd, uint msg, System.IntPtr wParam, System.IntPtr lParam)	Unknown
 	[Native to Managed Transition]	
 	user32.dll!00007fff347be858()	Unknown
 	user32.dll!00007fff347be3dc()	Unknown
 	user32.dll!00007fff347d0bc3()	Unknown
 	ntdll.dll!00007fff3612fbf4()	Unknown
 	win32u.dll!00007fff33901704()	Unknown
 	user32.dll!00007fff347be2ea()	Unknown
 	[Managed to Native Transition]	
 	Avalonia.Win32.dll!Avalonia.Win32.Win32Platform.RunLoop(System.Threading.CancellationToken cancellationToken)	Unknown
 	Avalonia.Base.dll!Avalonia.Threading.Dispatcher.MainLoop(System.Threading.CancellationToken cancellationToken)	Unknown
 	Avalonia.Controls.dll!Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(string[] args)	Unknown
 	Avalonia.Controls.dll!Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime<Avalonia.AppBuilder>(Avalonia.AppBuilder builder, string[] args, Avalonia.Controls.ShutdownMode shutdownMode)	Unknown
>	XamlControlsGallery.NetCore.dll!XamlControlsGallery.Program.Main(string[] args) Line 13	C#
 	[Native to Managed Transition]	
 	hostpolicy.dll!00007ffed5ea4e2d()	Unknown
 	hostpolicy.dll!00007ffed5eb2e27()	Unknown
 	hostpolicy.dll!00007ffed5eb2a36()	Unknown
 	hostpolicy.dll!00007ffed5eb4262()	Unknown
 	hostfxr.dll!00007ffed62c3aaa()	Unknown
 	hostfxr.dll!00007ffed62c7404()	Unknown
 	hostfxr.dll!00007ffed62c5c0b()	Unknown
 	hostfxr.dll!00007ffed62c20e9()	Unknown
 	XamlControlsGallery.NetCore.exe!00007ff6aa142361()	Unknown
 	XamlControlsGallery.NetCore.exe!00007ff6aa142758()	Unknown
 	XamlControlsGallery.NetCore.exe!00007ff6aa144608()	Unknown
 	kernel32.dll!00007fff35c66fd4()	Unknown
 	ntdll.dll!00007fff360dcec1()	Unknown

@kekekeks kekekeks modified the milestones: 0.10, 0.11 Dec 11, 2020
@Mikolaytis
Copy link
Contributor

CONTEXT_LOSS handling is a must have feature. Especially on a notebooks. After a sleep users are getting almost 100% repro. This is making them angry a lot :) App freeze/crash + potential progress loss is a pain.
I hope this feature will have a higher priority and will be fixed in near future. Thanks!

@radiolondra
Copy link

No progress on this? I encountered this issue today while simply resizing the main window of my app.

@Mikolaytis
Copy link
Contributor

@kekekeks as a quick solution - maybe let's handle CONTEXT_LOSS with exception? So we can handle it as unobserved exception, save all the changes in app and restart it.

Now device lost generates a freeze of app on MakeCurrent EGL method on windows - it's a disaster, because we can't handle this. Only solution now is to listen to Render Thread responsiveness from background thread and if there is a minute lag - restart the app.

@kekekeks
Copy link
Member

let's handle CONTEXT_LOSS with exception

  1. that exception would happen on the render thread
  2. UI thread might be in a blocking wait for the render thread to finish rendering (that currently only happens during resize or window close)

@jbosh
Copy link

jbosh commented Jul 20, 2022

I'm seeing this issue if I leave an application open and then put Windows to sleep. Upon wakeup, the exception will fire 100% of the time.

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

Successfully merging a pull request may close this issue.

7 participants