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.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cube/cube.c') diff --git a/cube/cube.c b/cube/cube.c index 5cd67866..08581070 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -366,6 +366,7 @@ struct demo { bool use_staging_buffer; bool separate_present_queue; bool is_minimized; + bool invalid_gpu_selection; int32_t gpu_number; bool VK_KHR_incremental_present_enabled; @@ -3391,7 +3392,7 @@ static void demo_init_vk(struct demo *demo) { VkPhysicalDevice *physical_devices = malloc(sizeof(VkPhysicalDevice) * gpu_count); err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, physical_devices); assert(!err); - if (demo->gpu_number >= 0 && !((uint32_t)demo->gpu_number < gpu_count)) { + if (demo->invalid_gpu_selection || (demo->gpu_number >= 0 && !((uint32_t)demo->gpu_number < gpu_count))) { fprintf(stderr, "GPU %d specified is not present, GPU count = %u\n", demo->gpu_number, gpu_count); ERR_EXIT("Specified GPU number is not present", "User Error"); } @@ -4041,7 +4042,7 @@ static void demo_init(struct demo *demo, int argc, char **argv) { } if ((strcmp(argv[i], "--gpu_number") == 0) && (i < argc - 1)) { demo->gpu_number = atoi(argv[i + 1]); - assert(demo->gpu_number >= 0); + if (demo->gpu_number < 0) demo->invalid_gpu_selection = true; i++; continue; } -- cgit v1.2.3