Skip to content

Commit 925833b

Browse files
committed
Clipper.Engine - fixed bug in ClipperBase.CheckSplitOwner. (#1029)
1 parent 618c05c commit 925833b

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

CPP/Clipper2Lib/src/clipper.engine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* Author : Angus Johnson *
3-
* Date : 11 October 2025 *
3+
* Date : 5 November 2025 *
44
* Website : https://www.angusj.com *
55
* Copyright : Angus Johnson 2010-2025 *
66
* Purpose : This is the main polygon clipping module *
@@ -2940,8 +2940,10 @@ namespace Clipper2Lib {
29402940

29412941
bool ClipperBase::CheckSplitOwner(OutRec* outrec, OutRecList* splits)
29422942
{
2943-
for (auto split : *splits)
2943+
// nb: use indexing (not an iterator) in case 'splits' is modified inside this loop (#1029)
2944+
for (size_t idx = 0; idx < splits->size(); ++idx)
29442945
{
2946+
OutRec* split = (*splits)[idx];
29452947
if (!split->pts && split->splits &&
29462948
CheckSplitOwner(outrec, split->splits)) return true; //#942
29472949
split = GetRealOutRec(split);

CSharp/Clipper2Lib/Clipper.Engine.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* Author : Angus Johnson *
3-
* Date : 11 October 2025 *
3+
* Date : 5 November 2025 *
44
* Website : https://www.angusj.com *
55
* Copyright : Angus Johnson 2010-2025 *
66
* Purpose : This is the main polygon clipping module *
@@ -3080,9 +3080,10 @@ private bool CheckBounds(OutRec outrec)
30803080

30813081
private bool CheckSplitOwner(OutRec outrec, List<int>? splits)
30823082
{
3083-
foreach (int i in splits!)
3083+
// nb: use indexing (not an iterator) in case 'splits' is modified inside this loop (#1029)
3084+
for (int i = 0; i < splits!.Count; i++)
30843085
{
3085-
OutRec? split = _outrecList[i];
3086+
OutRec? split = _outrecList[splits[i]];
30863087
if (split.pts == null && split.splits != null &&
30873088
CheckSplitOwner(outrec, split.splits)) return true; //#942
30883089
split = GetRealOutRec(split);

Delphi/Clipper2Lib/Clipper.Engine.pas

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

33
(*******************************************************************************
44
* Author : Angus Johnson *
5-
* Date : 11 October 2025 *
5+
* Date : 5 November 2025 *
66
* Website : https://www.angusj.com *
77
* Copyright : Angus Johnson 2010-2025 *
88
* Purpose : This is the main polygon clipping module *
@@ -3747,9 +3747,12 @@ function TClipperBase.CheckSplitOwner(outrec: POutRec; const splits: TOutRecArra
37473747
// returns true if a valid owner is found in splits
37483748
// (and also assigns it to outrec.owner)
37493749
Result := true;
3750-
for i := 0 to High(splits) do
3750+
// nb: use indexing (not an iterator) in case 'splits' is modified inside
3751+
// this loop, and also accommodate the length of splits changing (#1029)
3752+
i := 0;
3753+
while (i < Length(splits)) do
37513754
begin
3752-
split := splits[i];
3755+
split := splits[i]; inc(i);
37533756
if not Assigned(split.pts) and Assigned(split.splits) and
37543757
CheckSplitOwner(outrec, split.splits) then Exit; // Result := true (#942)
37553758

0 commit comments

Comments
 (0)