From 55ad2f3931a7fcc9f4c6ec7278c0480ab12eb906 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 21 Nov 2024 14:09:14 +0700 Subject: [PATCH] fix: fix empty string in gpus_in_use settings to select the correct variant --- web/hooks/useSettings.ts | 2 +- web/screens/Settings/Advanced/index.tsx | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/web/hooks/useSettings.ts b/web/hooks/useSettings.ts index 874381317..0f02d41af 100644 --- a/web/hooks/useSettings.ts +++ b/web/hooks/useSettings.ts @@ -53,7 +53,7 @@ export const useSettings = () => { const settings = await readSettings() if (runMode != null) settings.run_mode = runMode if (notify != null) settings.notify = notify - if (gpusInUse != null) settings.gpus_in_use = gpusInUse + if (gpusInUse != null) settings.gpus_in_use = gpusInUse.filter((e) => !!e) if (vulkan != null) { settings.vulkan = vulkan // GPU enabled, set run_mode to 'gpu' diff --git a/web/screens/Settings/Advanced/index.tsx b/web/screens/Settings/Advanced/index.tsx index 62a2aded0..114bb2460 100644 --- a/web/screens/Settings/Advanced/index.tsx +++ b/web/screens/Settings/Advanced/index.tsx @@ -207,7 +207,12 @@ const Advanced = () => { let updatedGpusInUse = [...gpusInUse] if (updatedGpusInUse.includes(gpuId)) { updatedGpusInUse = updatedGpusInUse.filter((id) => id !== gpuId) - if (gpuEnabled && updatedGpusInUse.length === 0) { + if ( + gpuEnabled && + updatedGpusInUse.length === 0 && + gpuId && + gpuId.trim() + ) { // Vulkan support only allow 1 active device at a time if (vulkanEnabled) { updatedGpusInUse = [] @@ -219,10 +224,10 @@ const Advanced = () => { if (vulkanEnabled) { updatedGpusInUse = [] } - updatedGpusInUse.push(gpuId) + if (gpuId && gpuId.trim()) updatedGpusInUse.push(gpuId) } setGpusInUse(updatedGpusInUse) - await saveSettings({ gpusInUse: updatedGpusInUse }) + await saveSettings({ gpusInUse: updatedGpusInUse.filter((e) => !!e) }) // Reload window to apply changes // This will trigger engine servers to restart window.location.reload()