fix(review): add recursion depth guard to group child resolution

Prevents stack overflow from corrupted data with circular group references.
This commit is contained in:
Hiren Kangad
2026-03-12 22:09:12 +05:30
parent ecd4408d8a
commit 69fcab717c
+3 -1
View File
@@ -41,7 +41,9 @@ function resolveGroupChild(
group: SceneItem,
worldX: number,
worldY: number,
depth = 0,
): SceneItem | null {
if (depth > 10) return null; // Guard against circular group references
const groupData = group.data as GroupObject;
// Collect children that exist in the scene, sorted front-to-back (highest z first)
@@ -59,7 +61,7 @@ function resolveGroupChild(
// Nested group — recurse
if (child.data.type === 'group') {
const nested = resolveGroupChild(scene, child, worldX, worldY);
const nested = resolveGroupChild(scene, child, worldX, worldY, depth + 1);
if (nested) return nested;
// No valid child inside nested group under this point — skip
continue;