Skip to content

Commit

Permalink
Fix crash when trying to assign entity that's not a component in with…
Browse files Browse the repository at this point in the history
… statement
  • Loading branch information
SanderMertens committed Sep 22, 2023
1 parent 819953c commit 5c29f9d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32122,7 +32122,7 @@ const char* plecs_parse_assign_with_stmt(

ecs_id_t id = state->with[with_frame];
ecs_id_record_t *idr = flecs_id_record_get(world, id);
const ecs_type_info_t *ti = idr->type_info;
const ecs_type_info_t *ti = idr ? idr->type_info : NULL;
if (!ti) {
char *typename = ecs_id_str(world, id);
ecs_parser_error(name, expr, ptr - expr,
Expand Down
2 changes: 1 addition & 1 deletion src/addons/plecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ const char* plecs_parse_assign_with_stmt(

ecs_id_t id = state->with[with_frame];
ecs_id_record_t *idr = flecs_id_record_get(world, id);
const ecs_type_info_t *ti = idr->type_info;
const ecs_type_info_t *ti = idr ? idr->type_info : NULL;
if (!ti) {
char *typename = ecs_id_str(world, id);
ecs_parser_error(name, expr, ptr - expr,
Expand Down
3 changes: 2 additions & 1 deletion test/addons/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@
"scope_w_auto_override_pair",
"pair_w_rel_var",
"pair_w_tgt_var",
"assembly_w_pair_w_this_var"
"assembly_w_pair_w_this_var",
"with_value_not_a_component"
]
}, {
"id": "Doc",
Expand Down
15 changes: 15 additions & 0 deletions test/addons/src/Plecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7537,3 +7537,18 @@ void Plecs_assembly_w_pair_w_this_var(void) {

ecs_fini(world);
}

void Plecs_with_value_not_a_component(void) {
ecs_world_t *world = ecs_init();

const char *expr =
LINE "with Foo{10} {\n"
LINE " Bar\n"
LINE "}\n"
LINE "\n";

ecs_log_set_level(-4);
test_assert(ecs_plecs_from_str(world, NULL, expr) != 0);

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/addons/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ void Plecs_scope_w_auto_override_pair(void);
void Plecs_pair_w_rel_var(void);
void Plecs_pair_w_tgt_var(void);
void Plecs_assembly_w_pair_w_this_var(void);
void Plecs_with_value_not_a_component(void);

// Testsuite 'Doc'
void Doc_get_set_name(void);
Expand Down Expand Up @@ -3351,6 +3352,10 @@ bake_test_case Plecs_testcases[] = {
{
"assembly_w_pair_w_this_var",
Plecs_assembly_w_pair_w_this_var
},
{
"with_value_not_a_component",
Plecs_with_value_not_a_component
}
};

Expand Down Expand Up @@ -7473,7 +7478,7 @@ static bake_test_suite suites[] = {
"Plecs",
NULL,
NULL,
227,
228,
Plecs_testcases
},
{
Expand Down

0 comments on commit 5c29f9d

Please sign in to comment.