Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ecs_struct gives error: xxx matches with actual type but alignment is different #1016

Closed
xubury opened this issue Aug 3, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@xubury
Copy link

xubury commented Aug 3, 2023

With the following code snippet, ecs_struct gives error:
error: meta.c: 283: computed size for 'versor' matches with actual type but alignment is different (4 vs. 16)

  typedef __attribute((aligned(16))) float versor[4];
  ECS_COMPONENT(ecs, versor);
  ecs_struct(ecs, {.entity  = ecs_id(versor),
                   .members = {{.name = "x", .type = ecs_id(ecs_f32_t)},
                               {.name = "y", .type = ecs_id(ecs_f32_t)},
                               {.name = "z", .type = ecs_id(ecs_f32_t)},
                               {.name = "w", .type = ecs_id(ecs_f32_t)}}});

 EcsComponent const *ptr = ecs_get(ecs, ecs_id(versor), EcsComponent);
 printf("%d", ptr->alignment); // output 16

Can anyone show me where I did wrong? Many thanks!

@xubury xubury added the bug Something isn't working label Aug 3, 2023
@xubury
Copy link
Author

xubury commented Aug 3, 2023

Found a workaround by doing this, it seems like alignment is mismatch with ECS_COMPONENT and ecs_struct?

  ecs_entity_t ecs_id(versor) = 0;
  ecs_id(versor) = ecs_array(ecs, {.entity = 0, .type = ecs_id(ecs_f32_t), .count = 4});
  ecs_get_mut(ecs, ecs_id(versor), EcsComponent)->alignment = 16; // serialization will be incorrect without this

@SanderMertens
Copy link
Owner

Yeah ECS_COMPONENT gets the actual alignment of a type, whereas ecs_struct calculates the alignment. This should be fixed, ecs_struct should not override the actual alignment of a type.

@SanderMertens
Copy link
Owner

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants