From 3bdccf37e67cd5c53f88fba55ca9c5cdabe2b01f Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 30 Mar 2020 13:07:15 +0100 Subject: [PATCH] Fix crash with eglGetDisplay(EGL_DEFAULT_DISPLAY) on linux * We'll try to get a default display when xlib is available, otherwise there's nothing we can do and keyboard input will not be available. --- renderdoc/driver/gl/egl_hooks.cpp | 12 +++++++++++- renderdoc/os/posix/linux/linux_stringio.cpp | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/renderdoc/driver/gl/egl_hooks.cpp b/renderdoc/driver/gl/egl_hooks.cpp index aa97237dc..a6af89cfb 100644 --- a/renderdoc/driver/gl/egl_hooks.cpp +++ b/renderdoc/driver/gl/egl_hooks.cpp @@ -162,7 +162,17 @@ HOOK_EXPORT EGLDisplay EGLAPIENTRY eglGetDisplay_renderdoc_hooked(EGLNativeDispl EnsureRealLibraryLoaded(); #if ENABLED(RDOC_LINUX) - Keyboard::UseUnknownDisplay((void *)display); + + // display can be EGL_DEFAULT_DISPLAY which is NULL, and unfortunately we don't have anything then + if(display) + Keyboard::UseUnknownDisplay((void *)display); + +// if xlib is compiled we can try to get the default display (which is what this will do) +#if ENABLED(RDOC_XLIB) + else + Keyboard::UseUnknownDisplay(XOpenDisplay(NULL)); +#endif + #endif return EGL.GetDisplay(display); diff --git a/renderdoc/os/posix/linux/linux_stringio.cpp b/renderdoc/os/posix/linux/linux_stringio.cpp index d0def39f0..63f5d896b 100644 --- a/renderdoc/os/posix/linux/linux_stringio.cpp +++ b/renderdoc/os/posix/linux/linux_stringio.cpp @@ -509,6 +509,9 @@ bool GetWaylandKeyState(int key) WindowingSystem UseUnknownDisplay(void *disp) { + if(disp == NULL) + return WindowingSystem::Unknown; + // could be wayland or xlib, try to detect. // both Display* and wl_display* are valid pointers, so dereference and read the first pointer // sized bytes