From 4142e57082df77ff77b4eda62af6dbd87591bcbb Mon Sep 17 00:00:00 2001 From: David Snopek Date: Thu, 22 Feb 2024 16:50:39 -0600 Subject: [PATCH] Fix crash when using OpenXR extension wrappers from GDExtension (cherry picked from commit 713ea0629a8c767e117836af4646cf88deca872a) --- modules/openxr/openxr_api.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index 3c606de6705..4d30b282dd1 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -1422,7 +1422,13 @@ void OpenXRAPI::register_extension_metadata() { void OpenXRAPI::cleanup_extension_wrappers() { for (OpenXRExtensionWrapper *extension_wrapper : registered_extension_wrappers) { - memdelete(extension_wrapper); + // Fix crash when the extension wrapper comes from GDExtension. + OpenXRExtensionWrapperExtension *gdextension_extension_wrapper = dynamic_cast(extension_wrapper); + if (gdextension_extension_wrapper) { + memdelete(gdextension_extension_wrapper); + } else { + memdelete(extension_wrapper); + } } registered_extension_wrappers.clear(); }