Skip to content

Commit

Permalink
#1275 Fix issue with command batching that prevents query rematching
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jul 18, 2024
1 parent aaaf30f commit 17216b3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -9828,6 +9828,10 @@ void flecs_cmd_batch_for_entity(
flecs_notify_on_add(world, table, start_table,
ECS_RECORD_TO_ROW(r->row), 1, &added, 0, set_mask, true);
flecs_defer_end(world, world->stages[0]);
if (r->row & EcsEntityIsTraversable) {
/* Update monitors since we didn't do this in flecs_commit. */
flecs_update_component_monitors(world, &added, NULL);
}
}

diff->added.array = added.array;
Expand Down
4 changes: 4 additions & 0 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -4832,6 +4832,10 @@ void flecs_cmd_batch_for_entity(
flecs_notify_on_add(world, table, start_table,
ECS_RECORD_TO_ROW(r->row), 1, &added, 0, set_mask, true);
flecs_defer_end(world, world->stages[0]);
if (r->row & EcsEntityIsTraversable) {
/* Update monitors since we didn't do this in flecs_commit. */
flecs_update_component_monitors(world, &added, NULL);
}
}

diff->added.array = added.array;
Expand Down
3 changes: 2 additions & 1 deletion test/query/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,8 @@
"match_empty_table_up_implicit_isa",
"match_empty_table_up_written_implicit_isa",
"match_empty_table_up_isa",
"match_empty_table_up_written_isa"
"match_empty_table_up_written_isa",
"up_after_add_batched_to_parent"
]
}, {
"id": "Cascade",
Expand Down
37 changes: 37 additions & 0 deletions test/query/src/Traversal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8716,3 +8716,40 @@ void Traversal_match_empty_table_up_written_isa(void) {

ecs_fini(world);
}

void Traversal_up_after_add_batched_to_parent(void) {
ecs_world_t *world = ecs_init();

ECS_TAG(world, Foo);
ECS_TAG(world, Bar);

ecs_query_t *q = ecs_query(world, {
.terms = {
{ .id = Foo, .src.id = EcsUp }
},
.cache_kind = cache_kind
});

test_assert(q != NULL);

ecs_entity_t e1 = ecs_new(world);
ecs_entity_t e2 = ecs_new(world);
ecs_add_pair(world, e2, EcsChildOf, e1);

ecs_defer_begin(world);
ecs_add(world, e1, Foo);
ecs_add(world, e1, Bar);
ecs_defer_end(world);

ecs_iter_t it = ecs_query_iter(world, q);
test_bool(true, ecs_query_next(&it));
test_int(it.count, 1);
test_uint(it.entities[0], e2);
test_uint(Foo, ecs_field_id(&it, 0));
test_uint(e1, ecs_field_src(&it, 0));
test_bool(true, ecs_field_is_set(&it, 0));

test_bool(false, ecs_query_next(&it));

ecs_fini(world);
}

0 comments on commit 17216b3

Please sign in to comment.