From ac66643346df76561ff85be741e2998290d43646 Mon Sep 17 00:00:00 2001 From: jhorv <38920027+jhorv@users.noreply.github.com> Date: Sun, 21 May 2023 15:39:06 -0400 Subject: [PATCH] Fix crash in SettingsViewModel when Vulkan isn't available (#4985) * fix crash when Vulkan isn't available * add VulkanRenderer.GetPhysicalDevices() overload that provides its own Vk API object and logs on failure * adjustments per AcK77 --- .../UI/ViewModels/SettingsViewModel.cs | 2 +- src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs | 19 +++++++++++++++++++ src/Ryujinx/Ui/Windows/SettingsWindow.cs | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs index 89392f6b2..d260b6fc7 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs @@ -311,7 +311,7 @@ namespace Ryujinx.Ava.UI.ViewModels { _gpuIds = new List(); List names = new(); - var devices = VulkanRenderer.GetPhysicalDevices(Vk.GetApi()); + var devices = VulkanRenderer.GetPhysicalDevices(); if (devices.Length == 0) { diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs index ffa1a1034..74267325c 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs @@ -599,6 +599,25 @@ namespace Ryujinx.Graphics.Vulkan return new HardwareInfo(GpuVendor, GpuRenderer); } + /// + /// Gets the available Vulkan devices using the default Vulkan API + /// object returned by + /// + /// + public static DeviceInfo[] GetPhysicalDevices() + { + try + { + return VulkanInitialization.GetSuitablePhysicalDevices(Vk.GetApi()); + } + catch (Exception ex) + { + Logger.Error?.PrintMsg(LogClass.Gpu, $"Error querying Vulkan devices: {ex.Message}"); + + return Array.Empty(); + } + } + public static DeviceInfo[] GetPhysicalDevices(Vk api) { try diff --git a/src/Ryujinx/Ui/Windows/SettingsWindow.cs b/src/Ryujinx/Ui/Windows/SettingsWindow.cs index 65175ff15..fbfbf527c 100644 --- a/src/Ryujinx/Ui/Windows/SettingsWindow.cs +++ b/src/Ryujinx/Ui/Windows/SettingsWindow.cs @@ -478,7 +478,7 @@ namespace Ryujinx.Ui.Windows if (Enum.Parse(_graphicsBackend.ActiveId) == GraphicsBackend.Vulkan) { - var devices = VulkanRenderer.GetPhysicalDevices(Vk.GetApi()); + var devices = VulkanRenderer.GetPhysicalDevices(); string preferredGpuIdFromConfig = ConfigurationState.Instance.Graphics.PreferredGpu.Value; string preferredGpuId = preferredGpuIdFromConfig; bool noGpuId = string.IsNullOrEmpty(preferredGpuIdFromConfig);