Skip to content

Android: Crash when configuring context #407

Description

@nickw1

Thanks once again for this great project!

As mentioned on #406 I have attempted to create an absolute basic hello world example using three.js, which has been further refactored since I opened that issue.

However one thing that I have discovered in my environment (Expo-based project using Expo 56, Pixel 3 running Android 15 (LineageOS) and running an Expo development build) is that I cannot configure the context.

Specifically the code (mentioned in the docs) to do this fails:

context.configure({
      device,
      format: navigator.gpu.getPreferredCanvasFormat(),
      alphaMode: "premultiplied"
})

with this error:

THREE.THREE.WebGPURenderer: WebGPU Device Lost:
Message: CreateAndroidSurfaceKHR failed with VK_ERROR_NATIVE_WINDOW_IN_USE_KHR

A bit of digging suggests that this is because the window is already associated with a Vulkan instance and you're trying to re-associate it with another.

If I remove the configure, my example works absolutely fine.

The example is the [hello world example at https://github.com/nickw1/react-native-webgpu-hello-world] (https://github.com/nickw1/react-native-webgpu-hello-world) mentioned in my previous issue.

Activity

  1. wcandillon commented on Jul 9, 2026

    @wcandillon
    Owner

    Hello 👋

    I wasn't able to reproduce the issue on my Pixel device but that makes sense. Anymore information available from the logs?

  2. nickw1 commented on Jul 9, 2026

    @nickw1
    Author

    Hi,

    I've got a little more info but the crash seems to be triggered by an unhandled error type rather than the error itself:

    Message: CreateAndroidSurfaceKHR failed with VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
     - While handling unexpected error type Internal when allowed errors are (Validation|DeviceLost).
        at CheckVkSuccessImpl (/home/runner/work/react-native-skia/react-native-skia/externals/dawn/src/dawn/native/vulkan/VulkanError.cpp:106)
    

    FWIW, JS stack trace is as below, but this is just error handling so not terribly useful:

    addLog (LogBoxData.js: 235:39)
    addConsoleLog (LogBox.js: 213:30)
    reactConsoleErrorHandler (ExceptionsManager.js: 248:58)
    console.level (setupDeveloperTools.js: 42:33)
    error (three.core.js: 2039:17)
    Renderer#_onDeviceLost (three.webgpu.js: 60418:8)
    device.lost.then$argument_0 (three.webgpu.js:83987:25)
    
  3. wcandillon commented on Jul 9, 2026

    @wcandillon
    Owner

    So that's interesting, what I am reading is that the device gets lost for some reason and from there we can cannot recover the canvas or some reason (maybe something that needed to be cleaned wasn't cleaned up, e.g canvas unconfigure). Am I reading this correctly? It would be interesting to know why the device gets lost, can you log the info parameter sent to device.lost.then$argument_0 (three.webgpu.js:83987:25)?

  4. nickw1 commented on Jul 10, 2026

    @nickw1
    Author

    That sounds about right. By my reading of the error logs, it looks like the error is thrown at the C++ level by Vulkan within Dawn, due to the window already being bound to Vulkan, and then intercepted by Three.js. The device presumably gets lost due to this error. It looks like when you create a Canvas, it binds the window to Vulkan and then when you configure the context, it tries to bind the window to Vulkan again, and this is the source of the error. I'd guess from this that context configuration needs to check whether the window is already bound to Vulkan, though this is just guesswork.

    The info parameter doesn't really provide any extra info. It includes a reason property which is unknown and a message property equal to the message above, ie. Message: CreateAndroidSurfaceKHR failed with VK_ERROR_NATIVE_WINDOW_IN_USE_KHR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions