From 1f73453aeca76cd04d7154c3bc82b6ebf64ba593 Mon Sep 17 00:00:00 2001 From: romner Date: Wed, 19 Jul 2023 15:34:23 +0200 Subject: [PATCH] Fix crashes when trying to open nth GPU box with only n-1 GPUs in the system --- src/btop_input.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/btop_input.cpp b/src/btop_input.cpp index d816bf5..ee0816b 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -272,9 +272,9 @@ namespace Input { else if (is_in(key, "5", "6", "7", "8", "9", "0")) { atomic_wait(Runner::active); Config::current_preset = -1; - auto key_i = std::stoi(key); - if (std::cmp_greater(key_i-4, Gpu::gpu_names.size())) return; - Config::toggle_box(std::string("gpu") + (char)((key_i == 0 ? 10 : (key_i-5)) + '0')); + auto key_i = key == "0" ? 10 : std::stoi(key); + if (std::cmp_greater(key_i-3, Gpu::gpu_names.size())) return; + Config::toggle_box(std::string("gpu") + (char)(key_i-5 + '0')); Draw::calcSizes(); Runner::run("all", false, true); return;