From bd71eb8681529ab70ff892b12128f8b7a5faa4c7 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Mon, 16 Jan 2017 17:43:33 +0200 Subject: [PATCH] [core] Fix ambiguous condition on the sort criteria The previous sorting criteria would sometimes allow C > B, B > A but A > C, making the internal std::sort code sometimes point to an invalid reference. Fixes #7737 --- src/mbgl/style/style.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 2d11d16b1..0b516f7b9 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -26,8 +26,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -409,9 +411,6 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const } } - const bool isLeft = std::abs(angle) > M_PI_2; - const bool isBottom = angle < 0; - for (const auto& layer : layers) { if (!layer->baseImpl->needsRendering(zoomHistory.lastZoom)) { continue; @@ -456,13 +455,14 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const [](auto& pair) { return std::ref(pair.second); }); if (symbolLayer) { std::sort(sortedTiles.begin(), sortedTiles.end(), - [isLeft, isBottom](const RenderTile& a, const RenderTile& b) { - bool sortX = a.id.canonical.x > b.id.canonical.x; - bool sortW = a.id.wrap > b.id.wrap; - bool sortY = a.id.canonical.y > b.id.canonical.y; - return - a.id.canonical.y != b.id.canonical.y ? (isLeft ? sortY : !sortY) : - a.id.wrap != b.id.wrap ? (isBottom ? sortW : !sortW) : (isBottom ? sortX : !sortX); + [angle](const RenderTile& a, const RenderTile& b) { + Point pa(a.id.canonical.x, a.id.canonical.y); + Point pb(b.id.canonical.x, b.id.canonical.y); + + auto par = util::rotate(pa, angle); + auto pbr = util::rotate(pb, angle); + + return std::tie(par.y, par.x) < std::tie(pbr.y, pbr.x); }); }