Browse Source

Fix crash running editor/launcher on Quest 2 over link cable (#46)

* Fix crash running editor/launcher on Quest 2 over link cable

Signed-off-by: moraaar <[email protected]>

* Addressing feedback

Signed-off-by: moraaar <[email protected]>

Signed-off-by: moraaar <[email protected]>
moraaar 2 years ago
parent
commit
da077d89d3
1 changed files with 20 additions and 12 deletions
  1. 20 12
      Gems/OpenXRVk/Code/Source/OpenXRVkDevice.cpp

+ 20 - 12
Gems/OpenXRVk/Code/Source/OpenXRVkDevice.cpp

@@ -90,19 +90,27 @@ namespace OpenXRVk
             return AZ::RHI::ResultCode::Fail;
         }
 
-        // Now that we have created the device, load the function pointers for it.
-        // NOTE: When passing a physical device to Vulkan glad loader it uses 'vkEnumerateDeviceExtensionProperties'
-        // to obtain device's extension, but that list doesn't match with the list returned by 'xrGetVulkanDeviceExtensionsKHR'
-        // which is used for OpenXR. This discrepancy results in the context indicating some extensions are available when they
-        // are really not supported in an OpenXR environment. To surpass this issue we're not passing the physical device.
-        bool functionsLoaded = xrVkInstance->GetFunctionLoader().LoadProcAddresses(
-            &xrVkInstance->GetContext(), xrVkInstance->GetNativeInstance(), VK_NULL_HANDLE/*xrVkInstance->GetActivePhysicalDevice()*/, m_xrVkDevice);
-        m_context = xrVkInstance->GetContext();
-        if (!functionsLoaded)
         {
-            ShutdownInternal();
-            AZ_Error("OpenXRVk", false, "Failed to initialize function loader for the device.");
-            return AZ::RHI::ResultCode::Fail;
+#if AZ_TRAIT_OS_IS_HOST_OS_PLATFORM
+            VkPhysicalDevice xrVkPhysicalDevice = xrVkInstance->GetActivePhysicalDevice();
+#else
+            // NOTE: When passing a physical device to Vulkan glad loader it uses 'vkEnumerateDeviceExtensionProperties'
+            // to obtain device's extension, but that list doesn't match with the list returned by 'xrGetVulkanDeviceExtensionsKHR'
+            // which is used for OpenXR. This discrepancy results in the context indicating some extensions are available when they
+            // are really not supported in an OpenXR environment. To surpass this issue we're not passing the physical device.
+            VkPhysicalDevice xrVkPhysicalDevice = VK_NULL_HANDLE;
+#endif
+
+            // Now that we have created the device, load the function pointers for it.
+            const bool functionsLoaded = xrVkInstance->GetFunctionLoader().LoadProcAddresses(
+                &xrVkInstance->GetContext(), xrVkInstance->GetNativeInstance(), xrVkPhysicalDevice, m_xrVkDevice);
+            m_context = xrVkInstance->GetContext();
+            if (!functionsLoaded)
+            {
+                ShutdownInternal();
+                AZ_Error("OpenXRVk", false, "Failed to initialize function loader for the device.");
+                return AZ::RHI::ResultCode::Fail;
+            }
         }
 
         //Populate the output data of the descriptor