diff --git a/src/viewport.cpp b/src/viewport.cpp index 63cde4ba32..447d1ced16 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -555,13 +555,26 @@ static void DoSetViewportPosition(Window *w, const int left, const int top, cons if (_networking) NetworkUndrawChatMessage(); - std::sort(_vp_redraw_regions.begin(), _vp_redraw_regions.end(), [&](const ViewportRedrawRegion &a, const ViewportRedrawRegion &b) { - if (a.coords.right <= b.coords.left && xo > 0) return true; - if (a.coords.left >= b.coords.right && xo < 0) return true; - if (a.coords.bottom <= b.coords.top && yo > 0) return true; - if (a.coords.top >= b.coords.bottom && yo < 0) return true; - return false; - }); + if (xo != 0) { + std::sort(_vp_redraw_regions.begin(), _vp_redraw_regions.end(), [&](const ViewportRedrawRegion &a, const ViewportRedrawRegion &b) { + if (a.coords.right <= b.coords.left && xo > 0) return true; + if (a.coords.left >= b.coords.right && xo < 0) return true; + return false; + }); + if (yo != 0) { + std::stable_sort(_vp_redraw_regions.begin(), _vp_redraw_regions.end(), [&](const ViewportRedrawRegion &a, const ViewportRedrawRegion &b) { + if (a.coords.bottom <= b.coords.top && yo > 0) return true; + if (a.coords.top >= b.coords.bottom && yo < 0) return true; + return false; + }); + } + } else { + std::sort(_vp_redraw_regions.begin(), _vp_redraw_regions.end(), [&](const ViewportRedrawRegion &a, const ViewportRedrawRegion &b) { + if (a.coords.bottom <= b.coords.top && yo > 0) return true; + if (a.coords.top >= b.coords.bottom && yo < 0) return true; + return false; + }); + } while (!_vp_redraw_regions.empty()) { const Rect &rect = _vp_redraw_regions.back().coords;