aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAwais Belal <awais_belal@mentor.com>2016-11-11 15:13:40 +0500
committerKarl Schultz <karl@lunarg.com>2016-11-14 10:35:11 -0700
commit1731acbd8ce5cdadf879117f92cd0b1d1388e440 (patch)
treea4539078df8dfa7f6cad5fae99eaa69c18339b88
parent4bac7a3e221c5dd943d8bb600fe21356342486c9 (diff)
downloadusermoji-1731acbd8ce5cdadf879117f92cd0b1d1388e440.tar.xz
vulkaninfo: fix segfault when DISPLAY is not set
Both xlib and xcb interfaces expect the DISPLAY environment variable to be set before creation of a window and the display creation mechanism would segfault if that is not the case and won't provide the user with details on what has to be done to correct the problem. We now handle such scenarios and exit cleanly after providing the user with some details. Signed-off-by: Awais Belal <awais_belal@mentor.com>
-rw-r--r--demos/vulkaninfo.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/demos/vulkaninfo.c b/demos/vulkaninfo.c
index 677a04c7..cc69ec18 100644
--- a/demos/vulkaninfo.c
+++ b/demos/vulkaninfo.c
@@ -912,6 +912,9 @@ static void app_create_xlib_window(struct app_instance *inst) {
long visualMask = VisualScreenMask;
int numberOfVisuals;
+ if (inst->xlib_display == NULL)
+ return;
+
XVisualInfo vInfoTemplate={};
vInfoTemplate.screen = DefaultScreen(inst->xlib_display);
XVisualInfo *visualInfo = XGetVisualInfo(inst->xlib_display, visualMask,
@@ -1508,6 +1511,12 @@ int main(int argc, char **argv) {
app_destroy_win32_window(&inst);
}
#endif
+#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
+ if (getenv("DISPLAY") == NULL) {
+ printf("'DISPLAY' environment variable not set... Exiting!\n");
+ goto out;
+ }
+#endif
//--XCB--
#ifdef VK_USE_PLATFORM_XCB_KHR
if (has_extension(VK_KHR_XCB_SURFACE_EXTENSION_NAME,
@@ -1528,6 +1537,10 @@ int main(int argc, char **argv) {
if (has_extension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
inst.global_extension_count, inst.global_extensions)) {
app_create_xlib_window(&inst);
+ if (inst.xlib_display == NULL) {
+ printf("'DISPLAY' variable not set correctly. Exiting!\n'");
+ goto out;
+ }
for (i = 0; i < gpu_count; i++) {
app_create_xlib_surface(&inst);
printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName);
@@ -1548,6 +1561,7 @@ int main(int argc, char **argv) {
printf("\n\n");
}
+out:
for (i = 0; i < gpu_count; i++)
app_gpu_destroy(&gpus[i]);