diff --git a/Modules/@babylonjs/react-native-windows/windows/include/XrContextHelperOpenXR.h b/Modules/@babylonjs/react-native-windows/windows/include/XrContextHelperOpenXR.h index 9e38947d3..e8f73023f 100644 --- a/Modules/@babylonjs/react-native-windows/windows/include/XrContextHelperOpenXR.h +++ b/Modules/@babylonjs/react-native-windows/windows/include/XrContextHelperOpenXR.h @@ -6,18 +6,29 @@ namespace BabylonReactNative { - bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, const facebook::jsi::Value& xrSession, IXrContextOpenXR*& xrContext) + bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, IXrContextOpenXR*& xrContext) { xrContext = nullptr; - if (!xrSession.isObject() || - !xrSession.asObject(jsiRuntime).hasProperty(jsiRuntime, "nativeXrContext") || - !xrSession.asObject(jsiRuntime).hasProperty(jsiRuntime, "nativeXrContextType") || - xrSession.asObject(jsiRuntime).getProperty(jsiRuntime, "nativeXrContextType").asString(jsiRuntime).utf8(jsiRuntime) != "OpenXR") + if (!jsiRuntime.global().hasProperty(jsiRuntime, "navigator")) { return false; } - auto nativeExtensionPtr = static_cast(xrSession.asObject(jsiRuntime).getProperty(jsiRuntime, "nativeXrContext").asNumber()); + auto navigator{ jsiRuntime.global().getProperty(jsiRuntime, "navigator").asObject(jsiRuntime) }; + if (!navigator.hasProperty(jsiRuntime, "xr")) + { + return false; + } + + auto nativeXr{ navigator.getProperty(jsiRuntime, "xr").asObject(jsiRuntime) }; + if (!nativeXr.hasProperty(jsiRuntime, "nativeXrContext") || + !nativeXr.hasProperty(jsiRuntime, "nativeXrContextType") || + nativeXr.getProperty(jsiRuntime, "nativeXrContextType").asString(jsiRuntime).utf8(jsiRuntime) != "OpenXR") + { + return false; + } + + auto nativeExtensionPtr = static_cast(nativeXr.getProperty(jsiRuntime, "nativeXrContext").asNumber()); xrContext = reinterpret_cast(nativeExtensionPtr); return true; }