Skip to content

Commit

Permalink
Don't reset query match counters until query has been iterated
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 17, 2023
1 parent 5e89c27 commit ce03c4f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -53736,6 +53736,8 @@ void flecs_query_sync_match_monitor(
}
}
}

query->prev_match_count = query->match_count;
}

/* Check if single match term has changed */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -55518,6 +55518,7 @@ bool ecs_query_next_table(
}

error:
query->match_count = query->prev_match_count;
ecs_iter_fini(it);
return false;
}
Expand Down Expand Up @@ -55732,6 +55733,7 @@ bool ecs_query_next_instanced(
}

done: error:
query->match_count = query->prev_match_count;
ecs_iter_fini(it);
return false;

Expand Down
6 changes: 4 additions & 2 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ void flecs_query_sync_match_monitor(
}
}
}

query->prev_match_count = query->match_count;
}

/* Check if single match term has changed */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2353,6 +2353,7 @@ bool ecs_query_next_table(
}

error:
query->match_count = query->prev_match_count;
ecs_iter_fini(it);
return false;
}
Expand Down Expand Up @@ -2567,6 +2568,7 @@ bool ecs_query_next_instanced(
}

done: error:
query->match_count = query->prev_match_count;
ecs_iter_fini(it);
return false;

Expand Down
7 changes: 4 additions & 3 deletions test/api/src/Query.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit ce03c4f

Please sign in to comment.