OpenXR: Prevent adding/removing extension wrappers after session start#109533
Merged
Repiteo merged 1 commit intogodotengine:masterfrom Sep 30, 2025
Merged
Conversation
m4gr3d
approved these changes
Aug 21, 2025
bdea0a1 to
4a24de2
Compare
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is related to my work on improving XR when Godot is rendering on a separate thread, but not entirely.
It is thread unsafe to add/remove extension wrappers from any of these
Vector<T>s because both the render and main thread loop over them, especially inOpenXRAPI::end_frame()which runs on the render thread and can't have data change out from under it.However, it's just unsafe in general to add/remove extension wrappers from these lists after an OpenXR session has started, even in a single-threaded context, because the state of all our OpenXR resources will get inconsistent if an extension wrapper runs some of its
on_*()methods, but not all of them.This PR aims to fix that!
There's two groups of extension lists:
OpenXRAPI::register_extension_wrapper()and::unregister_extension_wrapper()). This is the strictest case: we can't add or remove anything from this list after the OpenXR instance has been created (so, even before the session).OpenXRAPI::end_frame(). Those can't have any changes after the session has actually started (so, not just after the session has been created, but after the state has changed toXR_SESSION_STATE_READY). This is important because some pre-existing extensions add themselves to those lists right after the session is created (and remove themselves after the session is destroyed), and we need to not break themI've tested this with the
XR_FB_passthroughextension support from godot_openxr_vendors (which uses thecomposition_layer_providerslist), and all seems good. But it could still use some testing with other extensions that use the other lists to make sure this doesn't break any of them.