From 19a17b29187c11950e63711deabff34284100b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 21 Sep 2015 09:43:19 -0400 Subject: [PATCH] Prevent infinite loops through circular references of multiple intersections. --- src/path/PathItem.Boolean.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 8ac382f9..2fcc995a 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -215,15 +215,21 @@ PathItem.inject(new function() { // Link the new segment with the intersection on the other curve var inter = segment._intersection; if (inter) { - var other = inter._curve; - console.log('Link' - + ', seg: ' + segment._path._id + '.' + segment._index - + ', other: ' + other._path._id); - // Create a chain of possible intersections linked through _next - // First find the last intersection in the chain, then link it. - while (inter._next) - inter = inter._next; - inter._next = loc._intersection; + var other = inter._intersection, + next = loc._next; + while (next && next !== other) { + next = next._next; + } + if (!next) { + console.log('Link' + + ', seg: ' + segment._path._id + '.' + segment._index + + ', other: ' + inter._curve._path._id); + // Create a chain of possible intersections linked through _next + // First find the last intersection in the chain, then link it. + while (inter._next) + inter = inter._next; + inter._next = loc._intersection; + } } else { segment._intersection = loc._intersection; }