Skip to content

Commit

Permalink
Fix incorrectly initialized context in query engine
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 5, 2024
1 parent 8691e24 commit 464cc34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -66256,6 +66256,8 @@ void flecs_rule_set_match(
}

ecs_iter_t *it = ctx->it;
ecs_assert(column >= 0, ECS_INTERNAL_ERROR, NULL);
ecs_assert(column < table->type.count, ECS_INTERNAL_ERROR, NULL);
flecs_rule_it_set_column(it, field_index, column);
ecs_id_t matched = flecs_rule_it_set_id(it, table, field_index, column);
flecs_rule_set_vars(op, matched, ctx);
Expand Down Expand Up @@ -66398,6 +66400,9 @@ bool flecs_rule_with(
op_ctx->column = flecs_ito(int16_t, tr->index);
op_ctx->remaining = flecs_ito(int16_t, tr->count);
} else {
ecs_assert((op_ctx->remaining + op_ctx->column - 1) < table->type.count,
ECS_INTERNAL_ERROR, NULL);
ecs_assert(op_ctx->remaining >= 0, ECS_INTERNAL_ERROR, NULL);
if (--op_ctx->remaining <= 0) {
return false;
}
Expand Down Expand Up @@ -66742,6 +66747,8 @@ bool flecs_rule_self_up_with(
bool result;
if (id_only) {
result = flecs_rule_with_id(op, redo, ctx);
ecs_rule_and_ctx_t *op_ctx = flecs_op_ctx(ctx, and);
op_ctx->remaining = 1;
} else {
result = flecs_rule_with(op, redo, ctx);
}
Expand Down Expand Up @@ -68208,8 +68215,11 @@ bool flecs_rule_populate(
ecs_record_t *r = flecs_entities_get(ctx->world, src);
ecs_table_t *src_table = r->table;
if (src_table->column_map) {
ecs_assert(index <= src_table->type.count,
ECS_INTERNAL_ERROR, NULL);
int32_t column = src_table->column_map[index - 1];
if (column != -1) {
ecs_assert(column >= 0, ECS_INTERNAL_ERROR, NULL);
it->ptrs[i] = ecs_vec_get(
&src_table->data.columns[column].data,
it->sizes[i],
Expand Down
10 changes: 10 additions & 0 deletions src/addons/rules/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ void flecs_rule_set_match(
}

ecs_iter_t *it = ctx->it;
ecs_assert(column >= 0, ECS_INTERNAL_ERROR, NULL);
ecs_assert(column < table->type.count, ECS_INTERNAL_ERROR, NULL);
flecs_rule_it_set_column(it, field_index, column);
ecs_id_t matched = flecs_rule_it_set_id(it, table, field_index, column);
flecs_rule_set_vars(op, matched, ctx);
Expand Down Expand Up @@ -517,6 +519,9 @@ bool flecs_rule_with(
op_ctx->column = flecs_ito(int16_t, tr->index);
op_ctx->remaining = flecs_ito(int16_t, tr->count);
} else {
ecs_assert((op_ctx->remaining + op_ctx->column - 1) < table->type.count,
ECS_INTERNAL_ERROR, NULL);
ecs_assert(op_ctx->remaining >= 0, ECS_INTERNAL_ERROR, NULL);
if (--op_ctx->remaining <= 0) {
return false;
}
Expand Down Expand Up @@ -861,6 +866,8 @@ bool flecs_rule_self_up_with(
bool result;
if (id_only) {
result = flecs_rule_with_id(op, redo, ctx);
ecs_rule_and_ctx_t *op_ctx = flecs_op_ctx(ctx, and);
op_ctx->remaining = 1;
} else {
result = flecs_rule_with(op, redo, ctx);
}
Expand Down Expand Up @@ -2327,8 +2334,11 @@ bool flecs_rule_populate(
ecs_record_t *r = flecs_entities_get(ctx->world, src);
ecs_table_t *src_table = r->table;
if (src_table->column_map) {
ecs_assert(index <= src_table->type.count,
ECS_INTERNAL_ERROR, NULL);
int32_t column = src_table->column_map[index - 1];
if (column != -1) {
ecs_assert(column >= 0, ECS_INTERNAL_ERROR, NULL);
it->ptrs[i] = ecs_vec_get(
&src_table->data.columns[column].data,
it->sizes[i],
Expand Down

0 comments on commit 464cc34

Please sign in to comment.