From bafb0ac3dbe7683737081b70dcc70ee876e78e9e Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 23 Nov 2018 00:12:22 +0100 Subject: [PATCH] x11display: add x-init-threads var to call XInitThreads() This is off by default, but could be used if you stumble upon a race condition issue with X11 and threading. --- panda/src/x11display/config_x11display.cxx | 5 +++++ panda/src/x11display/config_x11display.h | 1 + panda/src/x11display/x11GraphicsPipe.cxx | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/panda/src/x11display/config_x11display.cxx b/panda/src/x11display/config_x11display.cxx index 4a633303ba..d31c4c1c23 100644 --- a/panda/src/x11display/config_x11display.cxx +++ b/panda/src/x11display/config_x11display.cxx @@ -40,6 +40,11 @@ ConfigVariableBool x_error_abort "of an error from the X window system. This can make it easier " "to discover where these errors are generated.")); +ConfigVariableBool x_init_threads +("x-init-threads", false, + PRC_DESC("Set this true to ask Panda3D to call XInitThreads() upon loading " + "the display module, which may help with some threading issues.")); + ConfigVariableInt x_wheel_up_button ("x-wheel-up-button", 4, PRC_DESC("This is the mouse button index of the wheel_up event: which " diff --git a/panda/src/x11display/config_x11display.h b/panda/src/x11display/config_x11display.h index bc40aad627..157f09c5fc 100644 --- a/panda/src/x11display/config_x11display.h +++ b/panda/src/x11display/config_x11display.h @@ -26,6 +26,7 @@ extern EXPCL_PANDAX11 void init_libx11display(); extern ConfigVariableString display_cfg; extern ConfigVariableBool x_error_abort; +extern ConfigVariableBool x_init_threads; extern ConfigVariableInt x_wheel_up_button; extern ConfigVariableInt x_wheel_down_button; diff --git a/panda/src/x11display/x11GraphicsPipe.cxx b/panda/src/x11display/x11GraphicsPipe.cxx index 2348d58706..479b3fde0c 100644 --- a/panda/src/x11display/x11GraphicsPipe.cxx +++ b/panda/src/x11display/x11GraphicsPipe.cxx @@ -66,6 +66,12 @@ x11GraphicsPipe(const std::string &display) : _im = (XIM)nullptr; _hidden_cursor = None; + // According to the documentation, we should call this before making any + // other Xlib calls if we wish to use the Xlib locking system. + if (x_init_threads) { + XInitThreads(); + } + install_error_handlers(); _display = XOpenDisplay(display_spec.c_str());