From e5b102b2d71518c14cb854b4a3abc4732fc524c7 Mon Sep 17 00:00:00 2001 From: harlekin Date: Tue, 23 Feb 2021 20:25:56 +0000 Subject: [PATCH] Fix: NPE that occurs when the config file specifies a GPU thats not available anymore --- src/com/sheepit/client/SettingsLoader.java | 7 +++++++ .../sheepit/client/standalone/swing/activity/Settings.java | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/com/sheepit/client/SettingsLoader.java b/src/com/sheepit/client/SettingsLoader.java index 11a4fdd..27f2f4d 100644 --- a/src/com/sheepit/client/SettingsLoader.java +++ b/src/com/sheepit/client/SettingsLoader.java @@ -35,6 +35,9 @@ import java.util.Set; import com.sheepit.client.Configuration.ComputeType; import com.sheepit.client.hardware.gpu.GPU; import com.sheepit.client.hardware.gpu.GPUDevice; +import com.sheepit.client.standalone.GuiSwing; +import com.sheepit.client.standalone.GuiText; +import com.sheepit.client.standalone.GuiTextOneLine; import lombok.Setter; public class SettingsLoader { @@ -399,6 +402,10 @@ public class SettingsLoader { // And now update the client configuration with the new value config.setRenderbucketSize(config.getGPUDevice().getRenderbucketSize()); } + else if (config.getUIType() != null && (config.getUIType().equals(GuiText.type) || config.getUIType().equals(GuiTextOneLine.type))) { + System.err.println("SettingsLoader::merge could not find specified GPU"); + System.exit(2); + } } else if (config.getGPUDevice() != null) { // The order of conditions is important to ensure the priority or app arguments, then the config file and finally the recommended size (if none diff --git a/src/com/sheepit/client/standalone/swing/activity/Settings.java b/src/com/sheepit/client/standalone/swing/activity/Settings.java index 2895e08..1f59237 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Settings.java +++ b/src/com/sheepit/client/standalone/swing/activity/Settings.java @@ -71,6 +71,8 @@ import com.sheepit.client.hardware.gpu.opencl.OpenCL; import com.sheepit.client.network.Proxy; import com.sheepit.client.os.OS; import com.sheepit.client.standalone.GuiSwing; +import com.sheepit.client.standalone.GuiText; +import com.sheepit.client.standalone.GuiTextOneLine; import com.sheepit.client.standalone.swing.components.CollapsibleJPanel; public class Settings implements Activity { @@ -316,7 +318,9 @@ public class Settings implements Activity { int maxRenderbucketSize = 128; int recommendedBucketSize = GPU.MIN_RENDERBUCKET_SIZE; - if (config.getComputeMethod() == ComputeType.GPU || config.getComputeMethod() == ComputeType.CPU_GPU) { + //When replacing gpus it can happen that the client can't find the one specified in the config anymore in which case config.getGPUDevice() + //returns null + if ((config.getComputeMethod() == ComputeType.GPU || config.getComputeMethod() == ComputeType.CPU_GPU) && config.getGPUDevice() != null) { GPULister gpu; if (config.getGPUDevice().getType().equals("CUDA")) {