aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amdfalconx86/recipes-graphics/vulkan/vulkan-loader-layers/0009-vulkaninfo.c-fix-segfault-when-DISPLAY-is-not-set.patch
blob: 25785ffbfc27d2994afb85c2bf00af743aed92e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From b73227e97086116e596206b22ce0356bfc9b0a2c Mon Sep 17 00:00:00 2001
From: Awais Belal <awais_belal@mentor.com>
Date: Fri, 11 Nov 2016 14:48:54 +0500
Subject: [PATCH] vulkaninfo.c: 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>
---
 demos/vulkaninfo.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/demos/vulkaninfo.c b/demos/vulkaninfo.c
index 324720c..da0a7c3 100644
--- a/demos/vulkaninfo.c
+++ b/demos/vulkaninfo.c
@@ -900,6 +900,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,
@@ -1488,6 +1491,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,
@@ -1508,6 +1517,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);
@@ -1528,6 +1541,7 @@ int main(int argc, char **argv) {
         printf("\n\n");
     }
 
+out:
     for (i = 0; i < gpu_count; i++)
         app_gpu_destroy(&gpus[i]);
 
-- 
1.9.1