From 02feae3697826e1f202f654cdba99b015df373d2 Mon Sep 17 00:00:00 2001 From: Andreas Bergmeier Date: Wed, 13 Sep 2017 15:55:16 +0200 Subject: [PATCH] demos: Add support for headless XCB For headless XCB we cannot create a surface. Simply ignore XCB if connection could not be established or any other error occured. Change-Id: I32db6aa3fc14887658d4290dcabbe8a1930cd8b3 --- demos/vulkaninfo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/demos/vulkaninfo.c b/demos/vulkaninfo.c index cfd0e0c..949bd00 100644 --- a/demos/vulkaninfo.c +++ b/demos/vulkaninfo.c @@ -930,9 +930,9 @@ static void AppCreateXcbWindow(struct AppInstance *inst) { inst->xcb_connection = xcb_connect(NULL, &scr); int conn_error = xcb_connection_has_error(inst->xcb_connection); if (conn_error) { - fprintf(stderr, "XCB failed to connect to the X server due to error:%d.\nExiting ...\n", conn_error); + fprintf(stderr, "XCB failed to connect to the X server due to error:%d.\n", conn_error); fflush(stderr); - exit(1); + inst->xcb_connection = NULL; } setup = xcb_get_setup(inst->xcb_connection); @@ -956,6 +956,10 @@ static void AppCreateXcbWindow(struct AppInstance *inst) { } static void AppCreateXcbSurface(struct AppInstance *inst) { + if (!inst->xcb_connection) { + return; + } + VkResult U_ASSERT_ONLY err; VkXcbSurfaceCreateInfoKHR xcb_createInfo; xcb_createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; @@ -968,6 +972,10 @@ static void AppCreateXcbSurface(struct AppInstance *inst) { } static void AppDestroyXcbWindow(struct AppInstance *inst) { + if (!inst->xcb_connection) { + return; // Nothing to destroy + } + xcb_destroy_window(inst->xcb_connection, inst->xcb_window); xcb_disconnect(inst->xcb_connection); } -- 2.7.4