Skip empty multipolygons in union_many() to avoid invalid R-tree box - #927
Merged
systemed merged 1 commit intoAug 29, 2026
Merged
Conversation
boost::geometry::envelope() of an empty multipolygon returns Boost's inverse initialisation box (min = +DBL_MAX, max = -DBL_MAX). Inserting that box into the R-tree trips the Boost.Geometry indexable validity check, aborting the run: boost/geometry/index/rtree.hpp:1661: Assertion `is_valid(...) && "Indexable is invalid"' failed. Clipping a polygon against a tile can legitimately produce an empty result, so ProcessObjects() can hand union_many() a vector whose entries are empty. An empty multipolygon cannot intersect anything and contributes nothing to the union, so skip it before the R-tree query and insert. Builds that define NDEBUG do not abort, but store the invalid box in the R-tree, which makes subsequent intersects() queries unreliable for that tile. The result is silently wrong output rather than a crash, so this affects release builds too. Reproduced on a planet dump at z13 in z6/0/14 (north-west Alaska, bbox -180,67.5,-172,71.5).
Owner
|
Thanks! I think this might be similar to 67f1e45 which is in a branch hopefully to be merged later today. I'll compare the two in practice. |
Owner
|
Yep, it's the same. I'll merge this, back out the fix in the declutter branch and then re-merge. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generating planet tiles crashes during the mbtile write phase with a
Boost.Geometry assertion:
boost/geometry/index/rtree.hpp:1661:
Assertion `(detail::is_valid(m_members.translator()(value)))
&& ("Indexable is invalid")' failed.
Aborted
Environment
Debian 13.6
libboost-dev 1.83.0.2+b2
git pull master to update my version with the commits of the last 3 months
make clean
make => NDEBUG not set so an assert causes abort() which results in the crash (while with NDEBUG this error is silently ignored)
planet dump of this week (Aug. 27), problematic tile extract attached
Cause
boost::geometry::envelope()of an empty multipolygon returns Boost's inverseinitialisation box —
min = +DBL_MAX,max = -DBL_MAX— which failsthe indexable validity check on insert.
Clipping a polygon against a tile boundary can legitimately produce an
empty result, so
ProcessObjects()(tile_worker.cpp:402) can handunion_many()a vector containing empty entries.Backtrace at the point of failure:
#4 ...rtree<...>::raw_insert (...) at boost/geometry/index/rtree.hpp:1661
#6 union_many (to_unify=std::vector of length 2) at src/geom.cpp:257
#7 ProcessObjects (...) at src/tile_worker.cpp:402
#8 ProcessLayer (..., zoom=13, ...) at src/tile_worker.cpp:496
with
to_unify[0].empty() == trueand the box printing as±1.7976931348623157e+308.Fix
Skip empty multipolygons before the R-tree query and insert. An empty
multipolygon cannot intersect anything and contributes nothing to the
union, so skipping it is semantically correct rather than just
silencing the assertion.
Why this matters for release builds
Builds that define
NDEBUG— including CMakeReleaseand mostdistribution packages — compile the assertion out. They do not abort,
but they do store the invalid box in the R-tree, which makes
subsequent
intersects()queries unreliable for that tile. Polygonsmay then be merged that should not be, or vice versa. The result is
silently incorrect output rather than a crash.
The Makefile build does not define
NDEBUG, which is why the problemsurfaces there.
Reproduction
Planet dump, z13 within
z6/0/14(north-west Alaska). A cut-downextract is enough (attached)