From ef2947b52c22acd5c1956cac71845dc6778d5dc3 Mon Sep 17 00:00:00 2001 From: Mike Weiblen Date: Tue, 13 Feb 2018 13:56:13 -0700 Subject: [PATCH] demos: ensure DISPLAY envar is valid If the DISPLAY environment variable is unset or null, the cube demo will emit "Cannot find a compatible Vulkan installable client driver (ICD)." That message is not helpful when attempting to resolve the issue, since the problem is with the envar, not the ICD. Change-Id: Idf145cf0da906a4a8352b5bb136f88d9c1bca90d --- demos/cube.c | 13 +++++++++++++ demos/cube.cpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/demos/cube.c b/demos/cube.c index e5b10b0..5fb79c9 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -2504,6 +2504,12 @@ static void demo_create_window(struct demo *demo) { } #elif defined(VK_USE_PLATFORM_XLIB_KHR) static void demo_create_xlib_window(struct demo *demo) { + const char *display_envar = getenv("DISPLAY"); + if (display_envar == NULL || display_envar[0] == '\0') { + printf("Environment variable DISPLAY requires a valid value.\nExiting ...\n"); + fflush(stdout); + exit(1); + } XInitThreads(); demo->display = XOpenDisplay(NULL); @@ -3764,6 +3770,13 @@ static void demo_init_connection(struct demo *demo) { xcb_screen_iterator_t iter; int scr; + const char *display_envar = getenv("DISPLAY"); + if (display_envar == NULL || display_envar[0] == '\0') { + printf("Environment variable DISPLAY requires a valid value.\nExiting ...\n"); + fflush(stdout); + exit(1); + } + demo->connection = xcb_connect(NULL, &scr); if (xcb_connection_has_error(demo->connection) > 0) { printf("Cannot find a compatible Vulkan installable client driver " diff --git a/demos/cube.cpp b/demos/cube.cpp index 1cd3205..f436cd5 100644 --- a/demos/cube.cpp +++ b/demos/cube.cpp @@ -971,6 +971,13 @@ Demo::Demo() xcb_screen_iterator_t iter; int scr; + const char *display_envar = getenv("DISPLAY"); + if (display_envar == nullptr || display_envar[0] == '\0') { + printf("Environment variable DISPLAY requires a valid value.\nExiting ...\n"); + fflush(stdout); + exit(1); + } + connection = xcb_connect(nullptr, &scr); if (xcb_connection_has_error(connection) > 0) { printf( @@ -2438,6 +2445,13 @@ Demo::Demo() #elif defined(VK_USE_PLATFORM_XLIB_KHR) void Demo::create_xlib_window() { + const char *display_envar = getenv("DISPLAY"); + if (display_envar == nullptr || display_envar[0] == '\0') { + printf("Environment variable DISPLAY requires a valid value.\nExiting ...\n"); + fflush(stdout); + exit(1); + } + XInitThreads(); display = XOpenDisplay(nullptr); long visualMask = VisualScreenMask; -- 2.7.4