JessyDL/paradigm

Investigate why alignas + ecs component leads to segfault in GCC

Closed this issue · 2 comments

When storing a type that has been aligned using alignas GCC will generate faulty code when fetching the data from a component pack.

example:

struct alignas(16) foo {
    float data[4];
};

state_t state{};

state.create<foo>(1);

state.declare([](info_t& info, pack<foo> pack){
    for(auto [value] : pack) {
        volatile auto copy = value; // <- segfault
    }
});

state.tick(std::chrono::duration<float>(1.0f));

CLang (13.0.0 /w libstdc++) has a similar issue, but the segfault happens earlier when the data is memcpy'd during state's prepare_system

Issue identified, cause is the thread based local cache the ECS state prepares for each worker as preparation before the system is ticked was not aligned correctly.