increase legalize stack
diff --git a/bench/run.cpp b/bench/run.cpp
index d48f041..0106b71 100644
--- a/bench/run.cpp
+++ b/bench/run.cpp
@@ -7,6 +7,7 @@
std::vector<double> generate_uniform(std::size_t n) {
std::vector<double> coords;
+ coords.reserve(2 * n);
std::srand(350);
double norm = static_cast<double>(RAND_MAX) / 1e3;
for (size_t i = 0; i < n; i++) {
@@ -35,5 +36,6 @@
BENCHMARK(BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond);
BENCHMARK(BM_uniform)->Arg(2000)->Arg(100000)->Arg(200000)->Arg(500000)->Arg(1000000)->Unit(benchmark::kMillisecond);
+// BENCHMARK(BM_uniform)->Arg(1000000 * 100)->Unit(benchmark::kMillisecond);
BENCHMARK_MAIN()
diff --git a/include/delaunator.hpp b/include/delaunator.hpp
index d24dc9b..e526e50 100644
--- a/include/delaunator.hpp
+++ b/include/delaunator.hpp
@@ -148,7 +148,9 @@
constexpr double EPSILON = std::numeric_limits<double>::epsilon();
constexpr std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();
-constexpr std::size_t LEGALIZE_STACK_SIZE = 128;
+
+//@see https://stackoverflow.com/questions/30208196/maximum-recursive-function-calls-in-c-c-before-stack-is-full-and-gives-a-segme
+constexpr std::size_t LEGALIZE_STACK_SIZE = 1024;
inline bool check_pts_equal(double x1, double y1, double x2, double y2) {
return std::fabs(x1 - x2) <= EPSILON &&
@@ -451,10 +453,6 @@
size_t size = 1;
while (i < size) {
- if (i >= LEGALIZE_STACK_SIZE) {
- throw std::runtime_error("Legalize stack overflow");
- }
-
auto const a = m_legalize_stack[i];
i++;
@@ -526,6 +524,10 @@
std::size_t br = b0 + (b + 1) % 3;
+ if (size + 2 >= (LEGALIZE_STACK_SIZE)) {
+ throw std::runtime_error("Legalize stack overflow");
+ }
+
if (i < size) {
//move elements down the stack
for (auto mi = size - 1; mi >= i; mi--) {