diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 3f2c0afc3..247b488bb 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -1502,11 +1502,11 @@ public: } private: + context vars; entity_type free_list; + std::vector epool; dense_map, identity> pools; std::vector groups; - std::vector epool; - context vars; }; } // namespace entt diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index 961c82c42..7f5afb970 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -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() != nullptr); + } + + ~destruction_order() { + *ctx_check = *ctx_check && (registry->ctx().find() != 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(entity))), (std::get<0>(cview.get(entity)))); } + +TEST(Registry, CtxAndPoolMemberDestructionOrder) { + auto registry = std::make_unique(); + const auto entity = registry->create(); + bool ctx_check = false; + + registry->ctx().emplace(); + registry->emplace(entity, *registry, ctx_check); + registry.reset(); + + ASSERT_TRUE(ctx_check); +}