Skip to content

Commit

Permalink
#1087 Fix segfault when enqueueing custom event
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Dec 3, 2023
1 parent 0d6c22e commit d87bc7b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21071,6 +21071,7 @@ void flecs_enqueue(
}

cmd->is._1.value = desc_cmd;
cmd->is._1.size = ECS_SIZEOF(ecs_event_desc_t);

if (desc->param || desc->const_param) {
ecs_assert(!(desc->const_param && desc->param), ECS_INVALID_PARAMETER,
Expand Down
1 change: 1 addition & 0 deletions src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ void flecs_enqueue(
}

cmd->is._1.value = desc_cmd;
cmd->is._1.size = ECS_SIZEOF(ecs_event_desc_t);

if (desc->param || desc->const_param) {
ecs_assert(!(desc->const_param && desc->param), ECS_INVALID_PARAMETER,
Expand Down
3 changes: 2 additions & 1 deletion test/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@
"enqueue_event_not_alive_w_data_copy_after_delete_during_merge",
"enqueue_event_not_deferred",
"enqueue_event_not_deferred_to_async",
"enqueue_custom_implicit_any"
"enqueue_custom_implicit_any",
"enqueue_custom_after_large_cmd"
]
}, {
"id": "New",
Expand Down
32 changes: 32 additions & 0 deletions test/api/src/Event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,3 +1385,35 @@ void Event_enqueue_custom_implicit_any(void) {

ecs_fini(world);
}

typedef struct LargeType {
char value[8888];
} LargeType;

void Event_enqueue_custom_after_large_cmd(void) {
ecs_world_t *world = ecs_mini();

ECS_COMPONENT(world, LargeType);
ECS_COMPONENT(world, Position);

ecs_defer_begin(world);
ecs_entity_t e = ecs_set(world, 0, LargeType, {{0}});
ecs_defer_end(world);
test_assert(ecs_has(world, e, LargeType));

printf("\n\n");

ecs_defer_begin(world);
Position p = {10, 20};
ecs_enqueue(world, &(ecs_event_desc_t) {
.entity = e,
.ids = &(ecs_type_t){ .count = 1, .array = (ecs_id_t[]){ ecs_id(LargeType) }},
.event = ecs_id(Position),
.param = &p,
});
ecs_defer_end(world);

printf("\n\n");

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void Event_enqueue_event_not_alive_w_data_copy_after_delete_during_merge(void);
void Event_enqueue_event_not_deferred(void);
void Event_enqueue_event_not_deferred_to_async(void);
void Event_enqueue_custom_implicit_any(void);
void Event_enqueue_custom_after_large_cmd(void);

// Testsuite 'New'
void New_setup(void);
Expand Down Expand Up @@ -3428,6 +3429,10 @@ bake_test_case Event_testcases[] = {
{
"enqueue_custom_implicit_any",
Event_enqueue_custom_implicit_any
},
{
"enqueue_custom_after_large_cmd",
Event_enqueue_custom_after_large_cmd
}
};

Expand Down Expand Up @@ -12994,7 +12999,7 @@ static bake_test_suite suites[] = {
"Event",
NULL,
NULL,
31,
32,
Event_testcases
},
{
Expand Down

0 comments on commit d87bc7b

Please sign in to comment.