Skip to content

Commit

Permalink
Fix issue with query traversal that could cause duplicate results
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 4, 2024
1 parent 5b65eb3 commit 8691e24
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -66642,6 +66642,8 @@ bool flecs_rule_up_select(
continue;
}

op_ctx->row = row;

down = op_ctx->down = flecs_rule_get_down_cache(ctx, &op_ctx->cache,
op_ctx->trav, entity, op_ctx->idr_with, self);
op_ctx->cache_elem = -1;
Expand Down
2 changes: 2 additions & 0 deletions src/addons/rules/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ bool flecs_rule_up_select(
continue;
}

op_ctx->row = row;

down = op_ctx->down = flecs_rule_get_down_cache(ctx, &op_ctx->cache,
op_ctx->trav, entity, op_ctx->idr_with, self);
op_ctx->cache_elem = -1;
Expand Down
1 change: 1 addition & 0 deletions test/addons/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,7 @@
"this_written_self_up_childof_pair_for_var_written",
"this_self_up_childof_pair_for_var_written_n_targets",
"this_written_self_up_childof_pair_for_var_written_n_targets",
"self_up_mixed_traversable",
"self_up_2_levels",
"not_up_disabled",
"up_2_rel_instances",
Expand Down
37 changes: 37 additions & 0 deletions test/addons/src/RulesTraversal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8200,3 +8200,40 @@ void RulesTraversal_this_written_cascade_childof_w_parent_flag(void) {

ecs_fini(world);
}

void RulesTraversal_self_up_mixed_traversable(void) {
ecs_world_t *world = ecs_mini();

ECS_TAG(world, TagA);

ecs_entity_t p1 = ecs_new_id(world);
ecs_entity_t p2 = ecs_new_id(world);
ecs_entity_t c = ecs_new_w_pair(world, EcsChildOf, p2);

ecs_add(world, p1, TagA);
ecs_add(world, p2, TagA);

ecs_rule_t *q = ecs_rule(world, {
.expr = "TagA(self|up(ChildOf))"
});

test_assert(q != NULL);

ecs_iter_t it = ecs_rule_iter(world, q);
test_bool(true, ecs_rule_next(&it));
test_int(2, it.count);
test_uint(p1, it.entities[0]);
test_uint(p2, it.entities[1]);
test_uint(0, ecs_field_src(&it, 1));

test_bool(true, ecs_rule_next(&it));
test_int(1, it.count);
test_uint(c, it.entities[0]);
test_uint(p2, ecs_field_src(&it, 1));

test_bool(false, ecs_rule_next(&it));

ecs_rule_fini(q);

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/addons/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,7 @@ void RulesTraversal_this_up_childof_pair_for_var_written(void);
void RulesTraversal_this_written_self_up_childof_pair_for_var_written(void);
void RulesTraversal_this_self_up_childof_pair_for_var_written_n_targets(void);
void RulesTraversal_this_written_self_up_childof_pair_for_var_written_n_targets(void);
void RulesTraversal_self_up_mixed_traversable(void);
void RulesTraversal_self_up_2_levels(void);
void RulesTraversal_not_up_disabled(void);
void RulesTraversal_up_2_rel_instances(void);
Expand Down Expand Up @@ -7357,6 +7358,10 @@ bake_test_case RulesTraversal_testcases[] = {
"this_written_self_up_childof_pair_for_var_written_n_targets",
RulesTraversal_this_written_self_up_childof_pair_for_var_written_n_targets
},
{
"self_up_mixed_traversable",
RulesTraversal_self_up_mixed_traversable
},
{
"self_up_2_levels",
RulesTraversal_self_up_2_levels
Expand Down Expand Up @@ -9238,7 +9243,7 @@ static bake_test_suite suites[] = {
"RulesTraversal",
NULL,
NULL,
92,
93,
RulesTraversal_testcases
},
{
Expand Down

0 comments on commit 8691e24

Please sign in to comment.