registry: fixed a bug that affects late group initialization (close #440)
This commit is contained in:
@@ -1405,12 +1405,8 @@ public:
|
||||
}
|
||||
} else {
|
||||
// we cannot iterate backwards because we want to leave behind valid entities in case of owned types
|
||||
std::for_each(std::get<0>(cpools).data(), std::get<0>(cpools).data() + std::get<0>(cpools).size(), [this, cpools, handler](const auto entity) {
|
||||
if(has<std::decay_t<Owned>..., std::decay_t<Get>...>(entity) && !any<Exclude...>(entity)) {
|
||||
if(const auto pos = handler->current; !(std::get<0>(cpools).index(entity) < ++handler->current)) {
|
||||
(std::get<pool_handler<std::decay_t<Owned>> &>(cpools).swap(std::get<pool_handler<std::decay_t<Owned>> &>(cpools).data()[pos], entity), ...);
|
||||
}
|
||||
}
|
||||
std::for_each(std::get<0>(cpools).data(), std::get<0>(cpools).data() + std::get<0>(cpools).size(), [this, handler](const auto entity) {
|
||||
handler->template maybe_valid_if<std::tuple_element_t<0, std::tuple<std::decay_t<Owned>...>>>(*this, entity);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1121,7 +1121,7 @@ TEST(OwningGroup, SignalRace) {
|
||||
ASSERT_EQ(registry.group<int>(entt::get<double>).size(), 1u);
|
||||
}
|
||||
|
||||
TEST(OwningGroup, AfterFact) {
|
||||
TEST(OwningGroup, StableLateInitialization) {
|
||||
entt::registry registry;
|
||||
|
||||
for(std::size_t i{}; i < 30u; ++i) {
|
||||
@@ -1133,3 +1133,20 @@ TEST(OwningGroup, AfterFact) {
|
||||
// thanks to @pgruenbacher for pointing out this corner case
|
||||
ASSERT_EQ((registry.group<int, char>().size()), 5u);
|
||||
}
|
||||
|
||||
TEST(OwningGroup, PreventEarlyOptOut) {
|
||||
entt::registry registry;
|
||||
|
||||
registry.assign<int>(registry.create(), 3);
|
||||
|
||||
const auto entity = registry.create();
|
||||
registry.assign<char>(entity, 'c');
|
||||
registry.assign<int>(entity, 2);
|
||||
|
||||
// thanks to @pgruenbacher for pointing out this corner case
|
||||
registry.group<char, int>().each([entity](const auto entt, const auto &c, const auto &i) {
|
||||
ASSERT_EQ(entity, entt);
|
||||
ASSERT_EQ(c, 'c');
|
||||
ASSERT_EQ(i, 2);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user