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:
@@ -41,7 +41,9 @@ function resolveGroupChild(
|
|||||||
group: SceneItem,
|
group: SceneItem,
|
||||||
worldX: number,
|
worldX: number,
|
||||||
worldY: number,
|
worldY: number,
|
||||||
|
depth = 0,
|
||||||
): SceneItem | null {
|
): SceneItem | null {
|
||||||
|
if (depth > 10) return null; // Guard against circular group references
|
||||||
const groupData = group.data as GroupObject;
|
const groupData = group.data as GroupObject;
|
||||||
|
|
||||||
// Collect children that exist in the scene, sorted front-to-back (highest z first)
|
// Collect children that exist in the scene, sorted front-to-back (highest z first)
|
||||||
@@ -59,7 +61,7 @@ function resolveGroupChild(
|
|||||||
|
|
||||||
// Nested group — recurse
|
// Nested group — recurse
|
||||||
if (child.data.type === 'group') {
|
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;
|
if (nested) return nested;
|
||||||
// No valid child inside nested group under this point — skip
|
// No valid child inside nested group under this point — skip
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user