diff --git a/flecs.c b/flecs.c index 187eb57e51..80cbbc6d7e 100644 --- a/flecs.c +++ b/flecs.c @@ -33137,6 +33137,8 @@ bool ecs_type_has_id( ecs_id_t id, bool owned) { + ecs_poly_assert(world, ecs_world_t); + return search_type(world, NULL, type, 0, id, owned ? 0 : EcsIsA, 0, 0, 0, NULL, NULL) != -1; } @@ -33161,6 +33163,8 @@ int32_t ecs_type_match( ecs_entity_t *subject_out, int32_t *count_out) { + ecs_poly_assert(world, ecs_world_t); + if (subject_out) { *subject_out = 0; } diff --git a/flecs.h b/flecs.h index 42f5eaaa89..72cee2ecde 100644 --- a/flecs.h +++ b/flecs.h @@ -17889,6 +17889,9 @@ inline void entity_view::each(const Func& func) const { template inline void entity_view::each(flecs::id_t pred, flecs::id_t obj, const Func& func) const { + flecs::world_t *real_world = const_cast( + ecs_get_world(m_world)); + const ecs_table_t *table = ecs_get_table(m_world, m_id); if (!table) { return; @@ -17909,7 +17912,7 @@ inline void entity_view::each(flecs::id_t pred, flecs::id_t obj, const Func& fun _ecs_vector_first(type, ECS_VECTOR_T(ecs_id_t))); while (-1 != (cur = ecs_type_match( - m_world, table, type, cur, pattern, 0, 0, 0, NULL, NULL))) + real_world, table, type, cur, pattern, 0, 0, 0, NULL, NULL))) { flecs::id ent(m_world, ids[cur]); func(ent); diff --git a/include/flecs/addons/cpp/impl/entity.hpp b/include/flecs/addons/cpp/impl/entity.hpp index e3cc5877ed..b95d91b917 100644 --- a/include/flecs/addons/cpp/impl/entity.hpp +++ b/include/flecs/addons/cpp/impl/entity.hpp @@ -142,6 +142,9 @@ inline void entity_view::each(const Func& func) const { template inline void entity_view::each(flecs::id_t pred, flecs::id_t obj, const Func& func) const { + flecs::world_t *real_world = const_cast( + ecs_get_world(m_world)); + const ecs_table_t *table = ecs_get_table(m_world, m_id); if (!table) { return; @@ -162,7 +165,7 @@ inline void entity_view::each(flecs::id_t pred, flecs::id_t obj, const Func& fun _ecs_vector_first(type, ECS_VECTOR_T(ecs_id_t))); while (-1 != (cur = ecs_type_match( - m_world, table, type, cur, pattern, 0, 0, 0, NULL, NULL))) + real_world, table, type, cur, pattern, 0, 0, 0, NULL, NULL))) { flecs::id ent(m_world, ids[cur]); func(ent); diff --git a/src/type.c b/src/type.c index c4e96dc88e..1109405003 100644 --- a/src/type.c +++ b/src/type.c @@ -128,6 +128,8 @@ bool ecs_type_has_id( ecs_id_t id, bool owned) { + ecs_poly_assert(world, ecs_world_t); + return search_type(world, NULL, type, 0, id, owned ? 0 : EcsIsA, 0, 0, 0, NULL, NULL) != -1; } @@ -152,6 +154,8 @@ int32_t ecs_type_match( ecs_entity_t *subject_out, int32_t *count_out) { + ecs_poly_assert(world, ecs_world_t); + if (subject_out) { *subject_out = 0; } diff --git a/test/cpp_api/project.json b/test/cpp_api/project.json index 7d3022afe4..b509e3d918 100644 --- a/test/cpp_api/project.json +++ b/test/cpp_api/project.json @@ -172,7 +172,8 @@ "child_of", "child_of_w_type", "id_get_entity", - "id_get_invalid_entity" + "id_get_invalid_entity", + "each_in_stage" ] }, { "id": "Pairs", diff --git a/test/cpp_api/src/Entity.cpp b/test/cpp_api/src/Entity.cpp index 7ee874db4d..251121cdf2 100644 --- a/test/cpp_api/src/Entity.cpp +++ b/test/cpp_api/src/Entity.cpp @@ -2963,3 +2963,30 @@ void Entity_id_get_invalid_entity() { id.entity(); } + +void Entity_each_in_stage() { + flecs::world world; + + struct Rel { }; + struct Obj { }; + + auto e = world.entity().add(); + test_assert((e.has())); + + world.staging_begin(); + + auto s = world.get_stage(0); + auto em = e.mut(s); + test_assert((em.has())); + + int count = 0; + + em.each([&](flecs::entity obj) { + count ++; + test_assert(obj == world.id()); + }); + + test_int(count, 1); + + world.staging_end(); +} diff --git a/test/cpp_api/src/main.cpp b/test/cpp_api/src/main.cpp index afdc698984..fb71718365 100644 --- a/test/cpp_api/src/main.cpp +++ b/test/cpp_api/src/main.cpp @@ -167,6 +167,7 @@ void Entity_child_of(void); void Entity_child_of_w_type(void); void Entity_id_get_entity(void); void Entity_id_get_invalid_entity(void); +void Entity_each_in_stage(void); // Testsuite 'Pairs' void Pairs_add_component_pair(void); @@ -1349,6 +1350,10 @@ bake_test_case Entity_testcases[] = { { "id_get_invalid_entity", Entity_id_get_invalid_entity + }, + { + "each_in_stage", + Entity_each_in_stage } }; @@ -3444,7 +3449,7 @@ static bake_test_suite suites[] = { "Entity", NULL, NULL, - 158, + 159, Entity_testcases }, {