From f777a1a3f5f92814f8b83fe0c22dbe461f11bed7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 15 Jul 2017 10:15:21 +0200 Subject: Better fix X11 BadValue crash bug which also prevents similar issues on non-X11 platforms. --- plugingui/nativewindow_x11.cc | 15 ++++----------- plugingui/window.cc | 11 +++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'plugingui') diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index 70053ca..5faecc1 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -33,8 +33,8 @@ #include #include #include +#include -#include #include #include @@ -249,16 +249,9 @@ void NativeWindowX11::redraw(const Rect& dirty_rect) auto x2 = dirty_rect.x2; auto y2 = dirty_rect.y2; - // Make sure we don't try to paint a rect backwards. - if(x1 > x2) - { - std::swap(x1, x2); - } - - if(y1 > y2) - { - std::swap(y1, y2); - } + // Assert that we don't try to paint a backwards rect. + assert(x1 <= x2); + assert(y1 <= y2); updateImageFromBuffer(x1, y1, x2, y2); diff --git a/plugingui/window.cc b/plugingui/window.cc index 099cb91..60ecf02 100644 --- a/plugingui/window.cc +++ b/plugingui/window.cc @@ -358,6 +358,17 @@ bool Window::updateBuffer() dirty_rect.x2 = std::min(wpixbuf.width, dirty_rect.x2); dirty_rect.y2 = std::min(wpixbuf.height, dirty_rect.y2); + // Make sure we don't try to paint a rect backwards. + if(dirty_rect.x1 > dirty_rect.x2) + { + std::swap(dirty_rect.x1, dirty_rect.x2); + } + + if(dirty_rect.y1 > dirty_rect.y2) + { + std::swap(dirty_rect.y1, dirty_rect.y2); + } + native->redraw(dirty_rect); needs_redraw = false; -- cgit v1.2.3