leetvr / hotham

Hotham is a tool for creating incredible standalone VR games.
Apache License 2.0
386 stars 28 forks source link

[Bug]: hotham-simulator on Linux crashes on exit #204

Open jmgao opened 2 years ago

jmgao commented 2 years ago

What happened?

It looks like destruction of XrContext leads to hotham-simulator crashing on linux.

test_xr_context_smoke_test which is literally just the following:

    #[test]
    pub fn test_xr_context_smoke_test() {
        XrContext::new().unwrap();
    }

crashes on linux (AMD) in State::destroy when calling destroy_swapchain. Commenting out destroy_swapchain (and destroy_surface to avoid a vulkan validation error) makes things no longer crash.

Version

latest

In which Hotham component are you seeing the problem on?

Simulator

What VR System are you seeing the problem on?

Other

What OS are you seeing the problem on?

Linux

Relevant log output

Finished test [unoptimized + debuginfo] target(s) in 0.05s
     Running unittests (/home/jmgao/Projects/v3/hotham/target/debug/deps/hotham-009eadd7dd1fbec7)

running 1 test
WARNING: radv is not a conformant Vulkan implementation, testing use only.
[HOTHAM_SIMULATOR] Created physical device: 0x7f960001a2b0
[HOTHAM_SIMULATOR] Done! Device created: 0x7f9600712070
[HOTHAM_SIMULATOR] enumerate_view_configuration_views called with: 2
[HOTHAM_SIMULATOR] Creating XR Swapchain..
[HOTHAM_SIMULATOR] ..done.
[HOTHAM_SIMULATOR] Building windows swapchain..
[HOTHAM_SIMULATOR] Creating window with visible true..
WINDOW SCALE FACTOR, 1.0
[HOTHAM_SIMULATOR] ..done.
[HOTHAM_SIMULATOR] Creating surface..
[HOTHAM_SIMULATOR] ..done
[HOTHAM_SIMULATOR] About to create swapchain..
[HOTHAM_SIMULATOR] Created swapchain: 0x120000000012. Sending..
[HOTHAM_SIMULATOR] Received swapchain: 0x120000000012
[HOTHAM_SIMULATOR] Creating descriptor sets..
[HOTHAM_SIMULATOR] Created descriptor pool 0x190000000019
[HOTHAM_SIMULATOR] Allocating descriptor sets with layouts: [0x1a000000001a, 0x1a000000001a, 0x1a000000001a]
[HOTHAM_SIMULATOR] Creating render pass..
[HOTHAM_SIMULATOR] ..done!
[HOTHAM_SIMULATOR] Creating pipelines..
[HOTHAM_SIMULATOR] ..done!
[HOTHAM_SIMULATOR] ..done
[HOTHAM_SIMULATOR] Returning with Swapchain(19791209299986)
[HOTHAM_SIMULATOR] Create action set called with "input"
[HOTHAM_SIMULATOR] Created path 0x7f9600896680 for /user/hand/left
[HOTHAM_SIMULATOR] Created path 0x7f9600896680 for /user/hand/right
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/left/input/grip/pose
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/left/input/aim/pose
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/right/input/grip/pose
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/right/input/aim/pose
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/left/input/squeeze/value
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/left/input/trigger/value
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/left/output/haptic
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/right/input/squeeze/value
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/right/input/trigger/value
[HOTHAM_SIMULATOR] Created path 0x7f96008ab710 for /user/hand/right/output/haptic
[HOTHAM_SIMULATOR] Created path 0x7f96008ab0c0 for /interaction_profiles/oculus/touch_controller
[HOTHAM_SIMULATOR] Created left hand space: SpaceState { name: "Left Hand", position: "x: -0.2, y: 1.4, z: -0.5", orientation: "x: 0.707, y: 0, z: 0, w: 0.707" }, Space(11407146275288697293)
[HOTHAM_SIMULATOR] Created left hand space: SpaceState { name: "Left Hand", position: "x: -0.2, y: 1.4, z: -0.5", orientation: "x: 0.707, y: 0, z: 0, w: 0.707" }, Space(2508067510750580967)
[HOTHAM_SIMULATOR] Created right hand space: SpaceState { name: "Right Hand", position: "x: 0.2, y: 1.4, z: -0.5", orientation: "x: 0.707, y: 0, z: 0, w: 0.707" }, Space(9823019420125182543)
[HOTHAM_SIMULATOR] Created left hand space: SpaceState { name: "Left Hand", position: "x: -0.2, y: 1.4, z: -0.5", orientation: "x: 0.707, y: 0, z: 0, w: 0.707" }, Space(12203213533413683905)
[HOTHAM_SIMULATOR] Attach action sets called
[HOTHAM_SIMULATOR] Destroy called..
[HOTHAM_SIMULATOR] Closed called!
[HOTHAM_SIMULATOR] Closed called!
[HOTHAM_SIMULATOR] Closed called!
[HOTHAM_SIMULATOR] Closed called!
[HOTHAM_SIMULATOR] Closed called!
error: test failed, to rerun pass '-p hotham --lib'

Caused by:
  process didn't exit successfully: `/home/jmgao/Projects/v3/hotham/target/debug/deps/hotham-009eadd7dd1fbec7 'resources::xr_context::tests::test_xr_context_smoke_test'` (signal: 11, SIGSEGV: invalid memory reference)

TODO

There's a couple things to be done here:

  1. We should not crash if we get ERROR_OUT_OF_DATE_KHR as a result of the user closing the window

  2. Separately to this, if the window is resized, then we need to rebuild the swapchain That would involve a couple of steps:

  3. Flagging to OpenXR that the application needs to rebuild the runtime (unknown)

  4. Rebuilding the Vulkan swapchain (a good overview is here: https://vulkan-tutorial.com/Drawing_a_triangle/Swap_chain_recreation)

kanerogers commented 2 years ago

Thanks so much for this @jmgao ❤️