Skip to content

create_surface failed with 'AndroidSurface failed: ERROR_NATIVE_WINDOW_IN_USE_KHR' #3788

@lazytiger

Description

@lazytiger

Short info header:

  • GFX version: 0.9
  • OS: Android
  • GPU: Mali-G76 MP10

I am trying to use gfx on the Android platform, but one problem after another, finally, I met the first gfx problem. My codes as the following

 let el = EventLoop::new();
    el.run(move |event, el, control_flow| {
        *control_flow = ControlFlow::Wait;
        match event {
            Event::Resumed => unsafe {
                log::info!("window resumed");
                let window_builder = WindowBuilder::new().with_title("hello");
                let window = ContextBuilder::new()
                    .build_windowed(window_builder, el)
                    .unwrap()
                    .make_current()
                    .unwrap();
                log::info!("windows created");
                let surface_extent = Extent2D {
                    width: 1024,
                    height: 768,
                };
                // The `instance` is an entry point to the graphics API. The `1` in the
                // call is a version number - we don't care about that for now.
                //
                // The `surface` is an abstraction of the OS window we're drawing into.
                // In `gfx`, it also manages the swap chain, which is a chain of
                // multiple images for us to render to. While one is being displayed, we
                // can write to another one - and then swap them, hence the name.
                //
                // The `adapter` represents a physical device. A graphics card for example.
                // The host may have more than one, but below, we just take the first.
                let (instance, surface, adapter) = {
                    let instance =
                        backend::Instance::create(APP_NAME, 1).expect("Backend not supported");
                    let surface = instance
                        .create_surface(window.window())
                        .expect("Failed to create surface for window");

                    let adapter = instance.enumerate_adapters().remove(0);

                    (instance, surface, adapter)
                };
[package]
name = "gars"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["lib", "cdylib"]

[target.'cfg(target_os="android")'.dependencies]
ndk-glue = { version = "0.5", features = ["logger"] }
gfx-backend-vulkan = "0.9"
#gfx-backend-gl = "0.9"

[dependencies]
glutin = { git = "https://github.com/rust-windowing/glutin.git", branch = "android-example" }
log = "0.4"
gfx-hal = "0.9"
byteorder = "1.4"
gfx_core = "0.9"

[target.'cfg(not(target_os="android"))'.dependencies]
chrono = "0.4"
fern = "0.6"
gfx-backend-dx11 = "0.9"
#gfx-backend-gl = "0.9"
shaderc = "0.7"

[package.metadata.android]
package_name = "com.babeltime.gars"
label = "android test"
fullscreen = true
build_targets = ["armv7-linux-androideabi", "aarch64-linux-android"]

[package.metadata.android.application_attributes]
"android:hardwareAccelerated" = "true"

I also tried to use gfx-backend-gl but create_surface also failed with 'BadAlloc'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions