Skip to content

Commit 444c2c4

Browse files
committed
increase legalize stack
1 parent 312eeae commit 444c2c4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

bench/run.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
std::vector<double> generate_uniform(std::size_t n) {
99
std::vector<double> coords;
10+
coords.reserve(2 * n);
1011
std::srand(350);
1112
double norm = static_cast<double>(RAND_MAX) / 1e3;
1213
for (size_t i = 0; i < n; i++) {
@@ -35,5 +36,6 @@ void BM_uniform(benchmark::State& state) {
3536

3637
BENCHMARK(BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond);
3738
BENCHMARK(BM_uniform)->Arg(2000)->Arg(100000)->Arg(200000)->Arg(500000)->Arg(1000000)->Unit(benchmark::kMillisecond);
39+
// BENCHMARK(BM_uniform)->Arg(1000000 * 100)->Unit(benchmark::kMillisecond);
3840

3941
BENCHMARK_MAIN()

include/delaunator.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ inline bool in_circle(
148148

149149
constexpr double EPSILON = std::numeric_limits<double>::epsilon();
150150
constexpr std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();
151-
constexpr std::size_t LEGALIZE_STACK_SIZE = 128;
151+
152+
//@see https://stackoverflow.com/questions/30208196/maximum-recursive-function-calls-in-c-c-before-stack-is-full-and-gives-a-segme
153+
constexpr std::size_t LEGALIZE_STACK_SIZE = 1024;
152154

153155
inline bool check_pts_equal(double x1, double y1, double x2, double y2) {
154156
return std::fabs(x1 - x2) <= EPSILON &&
@@ -451,10 +453,6 @@ std::size_t Delaunator::legalize(std::size_t ia) {
451453
size_t size = 1;
452454
while (i < size) {
453455

454-
if (i >= LEGALIZE_STACK_SIZE) {
455-
throw std::runtime_error("Legalize stack overflow");
456-
}
457-
458456
auto const a = m_legalize_stack[i];
459457
i++;
460458

@@ -526,6 +524,10 @@ std::size_t Delaunator::legalize(std::size_t ia) {
526524

527525
std::size_t br = b0 + (b + 1) % 3;
528526

527+
if (size + 2 >= (LEGALIZE_STACK_SIZE)) {
528+
throw std::runtime_error("Legalize stack overflow");
529+
}
530+
529531
if (i < size) {
530532
//move elements down the stack
531533
for (auto mi = size - 1; mi >= i; mi--) {

0 commit comments

Comments
 (0)