The fix resets the Android global vulkan context when running in XR mode to allow the XR module to drive the initialization via vulkan hooks.
This commit is contained in:
Fredia Huya-Kouadio 2026-02-12 14:14:23 -08:00
parent 20d58a38c6
commit 0ad63522d7
2 changed files with 18 additions and 0 deletions

View file

@ -715,6 +715,7 @@ void DisplayServerAndroid::free_vulkan_global_context() {
if (rendering_context_global != nullptr) {
memdelete(rendering_context_global);
rendering_context_global = nullptr;
rendering_context_global_checked = false;
}
}
#endif
@ -781,6 +782,7 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis
#ifdef VULKAN_ENABLED
if (rendering_driver == "vulkan") {
check_vulkan_global_context(true);
if (rendering_context_global == nullptr) {
ERR_PRINT("Can't initialize display server with Vulkan driver because no Vulkan context is available.");
r_error = ERR_UNAVAILABLE;

View file

@ -515,6 +515,22 @@ JNIEXPORT jobjectArray JNICALL Java_org_godotengine_godot_GodotLib_getRendererIn
rendering_driver_chosen = RenderingServer::get_singleton()->get_current_rendering_driver_name();
rendering_method = RenderingServer::get_singleton()->get_current_rendering_method();
}
#ifndef XR_DISABLED
// When running in XR mode, vulkan initialization must be done by the XR module, so we ensure that the vulkan
// global context is reset.
// Note: This is temporary workaround to address https://github.com/godotengine/godot/issues/115924
// A proper fix involves updating the Android init flow so that DisplayServerAndroid can update the Android surface
// type (vulkan or opengl) after it's initialized.
bool xr_enabled = false;
if (XRServer::get_xr_mode() == XRServer::XRMODE_DEFAULT) {
xr_enabled = GLOBAL_GET_CACHED(bool, "xr/shaders/enabled");
} else {
xr_enabled = XRServer::get_xr_mode() == XRServer::XRMODE_ON;
}
if (xr_enabled) {
DisplayServerAndroid::free_vulkan_global_context();
}
#endif // XR_DISABLED
#endif
String rendering_driver_source = rendering_source_to_string(OS::get_singleton()->get_current_rendering_driver_name_source());