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

Component arrays don't follow large type alignment (CPP) #1471

Closed
nimble0 opened this issue Dec 13, 2024 · 1 comment
Closed

Component arrays don't follow large type alignment (CPP) #1471

nimble0 opened this issue Dec 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nimble0
Copy link
Contributor

nimble0 commented Dec 13, 2024

Describe the bug
Components arrays for types with alignment of 64bytes+ are not aligned.

To Reproduce
Edited hello_world example:

#include <hello_world.h>
#include <iostream>
#include <type_traits>
#include <cstdint>

// Component types
struct alignas(256) Position {
	double x;
	double y;
};

template <typename T>
bool is_aligned(T* p)
{
	return reinterpret_cast<std::uintptr_t>(p) % std::alignment_of<T>::value == 0;
}

int main(int, char *[]) {
	// Create the world
	flecs::world ecs;

	auto e = ecs.entity()
		.set(Position{4, 4});

	std::cout << "Position alignment = " << std::alignment_of<Position>::value << "\n";

	ecs.query<Position>()
		.run([=](flecs::iter iter)
		{
			while(iter.next())
			{
				auto field = iter.field<Position>(0);
				std::cout << "Is aligned = " << is_aligned(&field[0]) << "\n";
			}
		});
}

Expected behavior

Position alignment = 256
Is aligned = 1

Actual behavior

Position alignment = 256
Is aligned = 0

Additional context
Compiler: gcc (GCC) 14.2.1 20240910

@nimble0 nimble0 added the bug Something isn't working label Dec 13, 2024
@SanderMertens
Copy link
Owner

Duplicate of #478

@SanderMertens SanderMertens marked this as a duplicate of #478 Dec 14, 2024
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