Это мой исходный код:
Код: Выделить всё
#include
#include
#include
#include
struct Position {
float x, y;
};
struct Velocity {
float dx, dy;
};
void worker(flecs::world& world, int id) {
auto stage = world.get_stage(id);
for (int i = 0; i < 5; i++) {
stage.entity()
.set({float(i), float(i)})
.set({1.0f, 0.5f});
}
}
int main() {
flecs::world world;
world.set_stage_count(4);
// Register components
world.component();
world.component();
// Launch multiple threads that update the world
std::vector threads;
for (int i = 0; i < 4; i++) {
threads.emplace_back(worker, std::ref(world), i);
}
for (auto& t : threads) t.join();
// Merge deferred operations into the main world
world.merge();
// Verify entities exist
world.each([](flecs::entity e, Position& p) {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79850995/error-when-creating-entitites-in-flecs-in-multiple-threads[/url]