From 1e9be2f740284cd05b5bc7b52a0a2e9e74248d27 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Tue, 12 Nov 2024 22:10:06 -0800 Subject: [PATCH] Avoid crash if the first bin gets clipped away --- clip.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/clip.cpp b/clip.cpp index cd41bda6..3b1c4617 100644 --- a/clip.cpp +++ b/clip.cpp @@ -1299,7 +1299,8 @@ static void handle_closepath_from_mvt(drawvec &geom) { } } -static void feature_out(std::vector const &features, mvt_layer &outlayer, +// returns true if a feature was output; false if it was clipped away +static bool feature_out(std::vector const &features, mvt_layer &outlayer, std::set const &keep, std::set const &exclude, std::vector const &exclude_prefix, @@ -1427,7 +1428,10 @@ static void feature_out(std::vector const &features, mvt_layer &ou } outlayer.features.push_back(std::move(outfeature)); + return true; } + + return false; } static struct preservecmp { @@ -1719,21 +1723,22 @@ mvt_tile assign_to_bins(mvt_tile &features, for (size_t i = 0; i < outfeatures.size(); i++) { if (outfeatures[i].size() > 1) { - feature_out(outfeatures[i], outlayer, - keep, exclude, exclude_prefix, attribute_accum, - accumulate_numeric, key_pool, buffer); - mvt_feature &nfeature = outlayer.features.back(); - mvt_value val; - val.type = mvt_uint; - val.numeric_value.uint_value = outfeatures[i].size() - 1; - - std::string attrname; - if (accumulate_numeric.size() == 0) { - attrname = "tippecanoe:count"; - } else { - attrname = accumulate_numeric + ":count"; + if (feature_out(outfeatures[i], outlayer, + keep, exclude, exclude_prefix, attribute_accum, + accumulate_numeric, key_pool, buffer)) { + mvt_feature &nfeature = outlayer.features.back(); + mvt_value val; + val.type = mvt_uint; + val.numeric_value.uint_value = outfeatures[i].size() - 1; + + std::string attrname; + if (accumulate_numeric.size() == 0) { + attrname = "tippecanoe:count"; + } else { + attrname = accumulate_numeric + ":count"; + } + outlayer.tag(nfeature, attrname, val); } - outlayer.tag(nfeature, attrname, val); } }