From b17374498fcd4612e758a911fb11a8c2d0451dc0 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Thu, 1 Dec 2022 11:25:11 -0600 Subject: cube & cubepp: Handle negative gpu selections Previously, a negative gpu number (other than -1) would cause the program to assert. It is simple enough to handle it gracefully, so best to do so. --- cube/cube.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cube/cube.cpp') diff --git a/cube/cube.cpp b/cube/cube.cpp index 94f91274..95dd5dc6 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -330,6 +330,7 @@ struct Demo { bool use_staging_buffer = false; bool use_xlib = false; bool separate_present_queue = false; + bool invalid_gpu_selection = false; int32_t gpu_number = 0; vk::Instance inst; @@ -902,7 +903,7 @@ void Demo::init(int argc, char **argv) { } if ((strcmp(argv[i], "--gpu_number") == 0) && (i < argc - 1)) { gpu_number = atoi(argv[i + 1]); - assert(gpu_number >= 0); + if (gpu_number < 0) invalid_gpu_selection = true; i++; continue; } @@ -1295,7 +1296,7 @@ void Demo::init_vk() { "vkEnumeratePhysicalDevices Failure"); } - if (gpu_number >= 0 && !(static_cast(gpu_number) < physical_devices.size())) { + if (invalid_gpu_selection || (gpu_number >= 0 && !(static_cast(gpu_number) < physical_devices.size()))) { fprintf(stderr, "GPU %d specified is not present, GPU count = %zu\n", gpu_number, physical_devices.size()); ERR_EXIT("Specified GPU number is not present", "User Error"); } -- cgit v1.2.3