Skip to content

Commit 4069f83

Browse files
SanderMertens#1980 Fix issue with recursively setting ParentDepth
1 parent c94331d commit 4069f83

5 files changed

Lines changed: 47 additions & 5 deletions

File tree

distr/flecs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40289,7 +40289,7 @@ void flecs_entities_update_childof_depth(
4028940289
ecs_component_record_t *tgt_cr = flecs_components_get(
4029040290
world, ecs_childof(tgt));
4029140291
if (!tgt_cr) {
40292-
return;
40292+
continue;
4029340293
}
4029440294

4029540295
flecs_component_update_childof_depth(world, tgt_cr, tgt, r);
@@ -40313,7 +40313,7 @@ void flecs_entities_update_childof_depth(
4031340313
ecs_component_record_t *tgt_cr = flecs_components_get(
4031440314
world, ecs_childof(tgt));
4031540315
if (!tgt_cr) {
40316-
return;
40316+
continue;
4031740317
}
4031840318

4031940319
ecs_record_t *r = flecs_entities_get(world, tgt);

src/storage/component_index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ void flecs_entities_update_childof_depth(
11451145
ecs_component_record_t *tgt_cr = flecs_components_get(
11461146
world, ecs_childof(tgt));
11471147
if (!tgt_cr) {
1148-
return;
1148+
continue;
11491149
}
11501150

11511151
flecs_component_update_childof_depth(world, tgt_cr, tgt, r);
@@ -1169,7 +1169,7 @@ void flecs_entities_update_childof_depth(
11691169
ecs_component_record_t *tgt_cr = flecs_components_get(
11701170
world, ecs_childof(tgt));
11711171
if (!tgt_cr) {
1172-
return;
1172+
continue;
11731173
}
11741174

11751175
ecs_record_t *r = flecs_entities_get(world, tgt);

test/core/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@
793793
"depth_after_parent_set_parent",
794794
"depth_after_parent_remove_parent",
795795
"depth_after_parent_remove_other_sibling_parent",
796+
"depth_after_parent_set_parent_sibling_traversable_no_children",
796797
"depth_after_parent_reparent",
797798
"depth_after_parent_reparent_different_depth",
798799
"depth_after_parent_set_parent_nested",

test/core/src/NonFragmentingChildOf.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,42 @@ void NonFragmentingChildOf_depth_after_parent_remove_other_sibling_parent(void)
16161616
ecs_fini(world);
16171617
}
16181618

1619+
void NonFragmentingChildOf_depth_after_parent_set_parent_sibling_traversable_no_children(void) {
1620+
ecs_world_t *world = ecs_mini();
1621+
1622+
ecs_entity_t root = ecs_new(world);
1623+
ecs_entity_t p = ecs_new(world);
1624+
ecs_entity_t c1 = ecs_insert(world, ecs_value(EcsParent, {p}));
1625+
ecs_entity_t c2 = ecs_insert(world, ecs_value(EcsParent, {p}));
1626+
ecs_add_id(world, c2, EcsOrderedChildren);
1627+
ecs_entity_t gc2 = ecs_insert(world, ecs_value(EcsParent, {c2}));
1628+
1629+
/* Make first sibling traversable without creating ChildOf record for it. */
1630+
ecs_new_w_pair(world, EcsIsA, c1);
1631+
1632+
ecs_entities_t children = ecs_get_ordered_children(world, p);
1633+
test_int(children.count, 2);
1634+
test_uint(children.ids[0], c1);
1635+
test_uint(children.ids[1], c2);
1636+
1637+
test_assert(ecs_has_id(world, c1, ecs_value_pair(EcsParentDepth, 1)));
1638+
test_assert(ecs_has_id(world, c2, ecs_value_pair(EcsParentDepth, 1)));
1639+
test_assert(ecs_has_id(world, gc2, ecs_value_pair(EcsParentDepth, 2)));
1640+
1641+
ecs_set(world, p, EcsParent, {root});
1642+
1643+
test_assert(ecs_has_id(world, c1, ecs_value_pair(EcsParentDepth, 2)));
1644+
test_assert(!ecs_has_id(world, c1, ecs_value_pair(EcsParentDepth, 1)));
1645+
1646+
test_assert(ecs_has_id(world, c2, ecs_value_pair(EcsParentDepth, 2)));
1647+
test_assert(!ecs_has_id(world, c2, ecs_value_pair(EcsParentDepth, 1)));
1648+
1649+
test_assert(ecs_has_id(world, gc2, ecs_value_pair(EcsParentDepth, 3)));
1650+
test_assert(!ecs_has_id(world, gc2, ecs_value_pair(EcsParentDepth, 2)));
1651+
1652+
ecs_fini(world);
1653+
}
1654+
16191655
void NonFragmentingChildOf_depth_after_parent_reparent(void) {
16201656
ecs_world_t *world = ecs_mini();
16211657

test/core/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ void NonFragmentingChildOf_depth_after_parent_remove(void);
761761
void NonFragmentingChildOf_depth_after_parent_set_parent(void);
762762
void NonFragmentingChildOf_depth_after_parent_remove_parent(void);
763763
void NonFragmentingChildOf_depth_after_parent_remove_other_sibling_parent(void);
764+
void NonFragmentingChildOf_depth_after_parent_set_parent_sibling_traversable_no_children(void);
764765
void NonFragmentingChildOf_depth_after_parent_reparent(void);
765766
void NonFragmentingChildOf_depth_after_parent_reparent_different_depth(void);
766767
void NonFragmentingChildOf_depth_after_parent_set_parent_nested(void);
@@ -6152,6 +6153,10 @@ bake_test_case NonFragmentingChildOf_testcases[] = {
61526153
"depth_after_parent_remove_other_sibling_parent",
61536154
NonFragmentingChildOf_depth_after_parent_remove_other_sibling_parent
61546155
},
6156+
{
6157+
"depth_after_parent_set_parent_sibling_traversable_no_children",
6158+
NonFragmentingChildOf_depth_after_parent_set_parent_sibling_traversable_no_children
6159+
},
61556160
{
61566161
"depth_after_parent_reparent",
61576162
NonFragmentingChildOf_depth_after_parent_reparent
@@ -15815,7 +15820,7 @@ static bake_test_suite suites[] = {
1581515820
"NonFragmentingChildOf",
1581615821
NULL,
1581715822
NULL,
15818-
238,
15823+
239,
1581915824
NonFragmentingChildOf_testcases
1582015825
},
1582115826
{

0 commit comments

Comments
 (0)