-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Android - Fix segfault crash when native surface is destroyed on vulkan #17921
Conversation
…dering queued on vulkan android
You can test this PR using the following package version. |
What happens to vulkan surface associated with android surface when android one gets destroyed? is it no longer valid? |
Also, when it's not possible to create a valid render target for the current state of the native surface, the platform backend is supposed to throw RenderTargetNotReadyException rather than ArgumentException |
I guess we silently try to re-create the surface/swapchain here: Avalonia/src/Avalonia.Vulkan/Interop/VulkanDisplay.cs Lines 229 to 246 in 0525455
|
readonly object _lock = new object(); | ||
private readonly Handler _handler; | ||
|
||
internal event EventHandler? SurfaceWindowCreated; | ||
|
||
IntPtr IPlatformHandle.Handle => Holder?.Surface?.Handle is { } handle ? | ||
IntPtr IPlatformHandle.Handle => _isSurfaceValid && Holder?.Surface?.Handle is { } handle ? | ||
AndroidFramebuffer.ANativeWindow_fromSurface(JNIEnv.Handle, handle) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaks memory, BTW. ANativeWindow_fromSurface
increases the reference counter for returned ANativeWindow object.
It's out of the scope of the current PR but should be addressed at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for the scope of the PR.
We need some general refactoring for our vulkan render target loss recovery code.
When the android native surface is destroying, accessing the khr surface returns a surface lost vulkan error. We handle that by trying to recreate the vulkan surface, but since there's no valid native surface, it crashes with segfault at 2 points. First point of failure is using ANativeWindow api to access the native window for the destroyed surface, which will cause a segfault. The second point of failure is creating an android khr surface using a null handle. |
The Opengl backend throws its own custom exception, |
What does the pull request do?
This pr checks for valid native surface on android when creating a vulkan surface.
What is the current behavior?
When android suspends an activity, all surfaces owned by that activity is destroyed. We do not do any checks on the validity if the surfaces when we start drawing and we try to create a khr surface using the handle of a destroyed surface, causing a segfault.
What is the updated/expected behavior with this PR?
How was the solution implemented (if it's not obvious)?
Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues