Skip to content

Commit

Permalink
#1366 Fix issue with C++ observers and up traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens authored Sep 20, 2024
1 parent c51cf55 commit 3095237
Show file tree
Hide file tree
Showing 12 changed files with 465 additions and 10 deletions.
5 changes: 5 additions & 0 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12784,6 +12784,7 @@ void flecs_emit_propagate_id(
it->other_table = NULL;
it->offset = 0;
it->count = entity_count;
it->up_fields = 1;
if (entity_count) {
it->entities = ecs_table_entities(table);
}
Expand Down Expand Up @@ -12822,6 +12823,7 @@ void flecs_emit_propagate_id(
}

it->event_cur = event_cur;
it->up_fields = 0;
}

static
Expand Down Expand Up @@ -13116,6 +13118,7 @@ void flecs_emit_forward_id(
it->sources[0] = tgt;
it->event_id = id;
ECS_CONST_CAST(int32_t*, it->sizes)[0] = 0; /* safe, owned by observer */
it->up_fields = 1;

int32_t storage_i = ecs_table_type_to_column_index(tgt_table, column);
if (storage_i != -1) {
Expand Down Expand Up @@ -13176,6 +13179,8 @@ void flecs_emit_forward_id(
it->trs[0] = base_tr;
}
}

it->up_fields = 0;
}

static
Expand Down
1 change: 0 additions & 1 deletion distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25737,7 +25737,6 @@ struct field_ptrs {
void populate_self(const ecs_iter_t *iter, size_t index, T, Targs... comps) {
fields_[index].ptr = ecs_field_w_size(iter, sizeof(A),
static_cast<int8_t>(index));
// fields_[index].is_ref = iter->sources[index] != 0;
fields_[index].is_ref = false;
ecs_assert(iter->sources[index] == 0, ECS_INTERNAL_ERROR, NULL);
populate_self(iter, index + 1, comps ...);
Expand Down
1 change: 0 additions & 1 deletion include/flecs/addons/cpp/delegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ struct field_ptrs {
void populate_self(const ecs_iter_t *iter, size_t index, T, Targs... comps) {
fields_[index].ptr = ecs_field_w_size(iter, sizeof(A),
static_cast<int8_t>(index));
// fields_[index].is_ref = iter->sources[index] != 0;
fields_[index].is_ref = false;
ecs_assert(iter->sources[index] == 0, ECS_INTERNAL_ERROR, NULL);
populate_self(iter, index + 1, comps ...);
Expand Down
5 changes: 5 additions & 0 deletions src/observable.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ void flecs_emit_propagate_id(
it->other_table = NULL;
it->offset = 0;
it->count = entity_count;
it->up_fields = 1;
if (entity_count) {
it->entities = ecs_table_entities(table);
}
Expand Down Expand Up @@ -319,6 +320,7 @@ void flecs_emit_propagate_id(
}

it->event_cur = event_cur;
it->up_fields = 0;
}

static
Expand Down Expand Up @@ -613,6 +615,7 @@ void flecs_emit_forward_id(
it->sources[0] = tgt;
it->event_id = id;
ECS_CONST_CAST(int32_t*, it->sizes)[0] = 0; /* safe, owned by observer */
it->up_fields = 1;

int32_t storage_i = ecs_table_type_to_column_index(tgt_table, column);
if (storage_i != -1) {
Expand Down Expand Up @@ -673,6 +676,8 @@ void flecs_emit_forward_id(
it->trs[0] = base_tr;
}
}

it->up_fields = 0;
}

static
Expand Down
3 changes: 3 additions & 0 deletions test/core/include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ typedef struct Probe {
ecs_entity_t e[MAX_ENTITIES];
ecs_entity_t c[MAX_INVOCATIONS][MAX_SYS_COLUMNS];
ecs_entity_t s[MAX_INVOCATIONS][MAX_SYS_COLUMNS];
ecs_flags32_t ref_fields;
ecs_flags32_t up_fields;
ecs_flags32_t row_fields;
void *param;
} Probe;

Expand Down
8 changes: 8 additions & 0 deletions test/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,14 @@
"register_callback_after_run_ctx",
"register_run_after_callback_ctx",
"on_add_after_new_w_table",
"ref_flag_term_1",
"ref_flag_term_2",
"forward_up_flag_term_1",
"forward_up_flag_term_2",
"propagate_up_flag_term_1",
"propagate_up_flag_term_2",
"row_flag_term_1",
"row_flag_term_2",
"cache_test_1",
"cache_test_2",
"cache_test_3",
Expand Down
Loading

0 comments on commit 3095237

Please sign in to comment.