From 544ef137ee927ea51c3ed697578732d965668512 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 24 Nov 2018 22:44:55 +0100 Subject: [PATCH] x11display: fix crash with multithreading and NVIDIA driver --- panda/src/x11display/x11GraphicsWindow.cxx | 17 +++++++++++++++++ panda/src/x11display/x11GraphicsWindow.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index 17f6ca0a2a..9a1555c27e 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -218,6 +218,23 @@ move_pointer(int device, int x, int y) { } } +/** + * Clears the entire framebuffer before rendering, according to the settings + * of get_color_clear_active() and get_depth_clear_active() (inherited from + * DrawableRegion). + * + * This function is called only within the draw thread. + */ +void x11GraphicsWindow:: +clear(Thread *current_thread) { + if (is_any_clear_active()) { + // Evidently the NVIDIA driver may call glXCreateNewContext inside + // prepare_display_region, so we need to hold the X11 lock. + LightReMutexHolder holder(x11GraphicsPipe::_x_mutex); + GraphicsOutput::clear(current_thread); + } +} + /** * This function will be called within the draw thread before beginning * rendering for a given frame. It should do whatever setup is required, and diff --git a/panda/src/x11display/x11GraphicsWindow.h b/panda/src/x11display/x11GraphicsWindow.h index 078b016262..906a64b623 100644 --- a/panda/src/x11display/x11GraphicsWindow.h +++ b/panda/src/x11display/x11GraphicsWindow.h @@ -36,6 +36,8 @@ public: virtual MouseData get_pointer(int device) const; virtual bool move_pointer(int device, int x, int y); + + virtual void clear(Thread *current_thread); virtual bool begin_frame(FrameMode mode, Thread *current_thread); virtual void end_frame(FrameMode mode, Thread *current_thread);