diff --git a/flecs.c b/flecs.c index fd4f88e253..13dc467a5a 100644 --- a/flecs.c +++ b/flecs.c @@ -53736,6 +53736,8 @@ void flecs_query_sync_match_monitor( } } } + + query->prev_match_count = query->match_count; } /* Check if single match term has changed */ @@ -55315,8 +55317,6 @@ ecs_iter_t ecs_query_iter( flecs_eval_component_monitors(world); } - query->prev_match_count = query->match_count; - /* Prepare iterator */ int32_t table_count; @@ -55518,6 +55518,7 @@ bool ecs_query_next_table( } error: + query->match_count = query->prev_match_count; ecs_iter_fini(it); return false; } @@ -55732,6 +55733,7 @@ bool ecs_query_next_instanced( } done: error: + query->match_count = query->prev_match_count; ecs_iter_fini(it); return false; diff --git a/src/query.c b/src/query.c index cc1691d086..1afe39eaa9 100644 --- a/src/query.c +++ b/src/query.c @@ -571,6 +571,8 @@ void flecs_query_sync_match_monitor( } } } + + query->prev_match_count = query->match_count; } /* Check if single match term has changed */ @@ -2150,8 +2152,6 @@ ecs_iter_t ecs_query_iter( flecs_eval_component_monitors(world); } - query->prev_match_count = query->match_count; - /* Prepare iterator */ int32_t table_count; @@ -2353,6 +2353,7 @@ bool ecs_query_next_table( } error: + query->match_count = query->prev_match_count; ecs_iter_fini(it); return false; } @@ -2567,6 +2568,7 @@ bool ecs_query_next_instanced( } done: error: + query->match_count = query->prev_match_count; ecs_iter_fini(it); return false; diff --git a/test/api/src/Query.c b/test/api/src/Query.c index 143cf01783..56c09c0235 100644 --- a/test/api/src/Query.c +++ b/test/api/src/Query.c @@ -2384,8 +2384,9 @@ void Query_query_changed_after_delete() { test_assert(ecs_query_changed(q, 0) == true); it = ecs_query_iter(world, q); + test_assert(ecs_query_changed(q, 0) == true); + while (ecs_query_next(&it)) { } test_assert(ecs_query_changed(q, 0) == false); - ecs_iter_fini(&it); ecs_fini(world); } @@ -2402,7 +2403,7 @@ void Query_query_changed_after_add() { test_assert(ecs_query_changed(q, 0) == true); ecs_iter_t it = ecs_query_iter(world, q); - test_assert(ecs_query_changed(q, 0) == false); + test_assert(ecs_query_changed(q, 0) == true); while (ecs_query_next(&it)) { } test_assert(ecs_query_changed(q, 0) == false); @@ -2438,7 +2439,7 @@ void Query_query_changed_after_remove() { test_assert(ecs_query_changed(q, 0) == true); it = ecs_query_iter(world, q); - test_assert(ecs_query_changed(q, 0) == false); + test_assert(ecs_query_changed(q, 0) == true); while (ecs_query_next(&it)) { } test_assert(ecs_query_changed(q, 0) == false);