registry: update (and test) member destruction order (#930)
This commit is contained in:
committed by
Michele Caini
parent
5742100973
commit
6eff5a88f6
@@ -1502,11 +1502,11 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
context vars;
|
||||
entity_type free_list;
|
||||
std::vector<entity_type, allocator_type> epool;
|
||||
dense_map<id_type, std::unique_ptr<base_type>, identity> pools;
|
||||
std::vector<group_data> groups;
|
||||
std::vector<entity_type, allocator_type> epool;
|
||||
context vars;
|
||||
};
|
||||
|
||||
} // namespace entt
|
||||
|
||||
@@ -69,6 +69,24 @@ struct owner {
|
||||
const entt::registry *parent{nullptr};
|
||||
};
|
||||
|
||||
struct destruction_order {
|
||||
using ctx_check_type = int;
|
||||
|
||||
destruction_order(const entt::registry &ref, bool &ctx)
|
||||
: registry{&ref},
|
||||
ctx_check{&ctx} {
|
||||
*ctx_check = (registry->ctx().find<int>() != nullptr);
|
||||
}
|
||||
|
||||
~destruction_order() {
|
||||
*ctx_check = *ctx_check && (registry->ctx().find<int>() != nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
const entt::registry *registry;
|
||||
bool *ctx_check{};
|
||||
};
|
||||
|
||||
TEST(Registry, Context) {
|
||||
entt::registry registry;
|
||||
auto &ctx = registry.ctx();
|
||||
@@ -2170,3 +2188,15 @@ TEST(Registry, NoEtoType) {
|
||||
|
||||
ASSERT_EQ((std::get<0>(view.get<no_eto_type, int>(entity))), (std::get<0>(cview.get<const no_eto_type, const int>(entity))));
|
||||
}
|
||||
|
||||
TEST(Registry, CtxAndPoolMemberDestructionOrder) {
|
||||
auto registry = std::make_unique<entt::registry>();
|
||||
const auto entity = registry->create();
|
||||
bool ctx_check = false;
|
||||
|
||||
registry->ctx().emplace<typename destruction_order::ctx_check_type>();
|
||||
registry->emplace<destruction_order>(entity, *registry, ctx_check);
|
||||
registry.reset();
|
||||
|
||||
ASSERT_TRUE(ctx_check);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user