Skip to content

Incorrect memory alignment of components. #478

@RobertBiehl

Description

@RobertBiehl

Describe the bug
Component structs passed to system do not adhere to the defined memory alignment correctly.

To Reproduce

  1. enable avx

  2. Create component with aligned struct, e.g.

typedef struct EcsTransform3 {
    __attribute((aligned(32))) mat4 value;
} EcsTransform3;
  1. Inside system check address of pointer to struct
void TestSystem(ecs_iter_t* it) {
    EcsTransform3 *transform = ecs_term(it, EcsTransform3, 1);
    printf("(EcsTransform3 *) addr = %#010x", transform);
}

Sometimes prints addresses not aligned to 32 bytes as expected from CGLM_ALIGN_MAT.
(In my case this was 0x000000011af54ef0, which is only divisible by 16, not by 32.)
This causes crashes in calls to AVX intrinsics.

Expected behavior
Address of component should be aligned correctly, in this case to 32 bytes.

Additional context
Add any other context about the problem here (operating system, hardware, ...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas a workaroundIt's a bug, but there's a workaround

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions