Skip to content

Commit

Permalink
Make context not-current after rendering to prevent "already connecte…
Browse files Browse the repository at this point in the history
…d" on ANGLE

Some phones no longer have a native (E)GL implementation but use
ANGLE on top of Vulkan, which is more strict about Vulkan/NativeWindow
surfaces that have lingering references from an existing EGL Surface.
This is especially problematic with this app that simply recreates the
EGL surface every time the callback is called, e.g. in surface creation,
"change", and resize:

  E  [SurfaceView[rust.androidnativesurface/rust.androidnativesurface.MainActivity]@0#1(BLAST Consumer)1](id:5c2300000001,api:1,p:23587,c:23587) connect: already connected (cur=1 req=1)
  E  native_window_api_connect() failed: Invalid argument (-22)
  D  ANGLE Info:Debug.cpp:490 (insertMessage): EGL ERROR: eglPlatformCreateWindowSurface: Internal Vulkan error (-1000000001): The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API, in ../../src/libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.cpp, createSurfaceVk:133.
  I  thread '<unnamed>' panicked at src/support.rs:36:78:
  I  called `Result::unwrap()` on an `Err` value: Error { raw_code: Some(12301), raw_os_message: None, kind: BadSurface }

This is simply fixed by un-currentling the current context and the
surface associated with it.
  • Loading branch information
MarijnS95 committed Dec 7, 2023
1 parent ad89dcd commit 620360d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion android_native_surface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ fn render_to_native_window(window: NativeWindow) {

renderer.draw();

gl_window.surface.swap_buffers(&gl_context).unwrap();
gl_window
.surface
.swap_buffers(&gl_context)
.expect("Cannot swap buffers");

gl_context
.make_not_current()
.expect("Cannot uncurrent GL context");
}

#[no_mangle]
Expand Down

0 comments on commit 620360d

Please sign in to comment.