Pārlūkot izejas kodu

snapshot: refine the check in the constructor of the loader class - close #1106

Michele Caini 2 gadi atpakaļ
vecāks
revīzija
2d3fa3e51a
2 mainītis faili ar 6 papildinājumiem un 1 dzēšanām
  1. 1 1
      src/entt/entity/snapshot.hpp
  2. 5 0
      test/entt/entity/snapshot.cpp

+ 1 - 1
src/entt/entity/snapshot.hpp

@@ -164,7 +164,7 @@ public:
     basic_snapshot_loader(registry_type &source) noexcept
     basic_snapshot_loader(registry_type &source) noexcept
         : reg{&source} {
         : reg{&source} {
         // restoring a snapshot as a whole requires a clean registry
         // restoring a snapshot as a whole requires a clean registry
-        ENTT_ASSERT(reg->template storage<entity_type>().empty() && (reg->storage().begin() == reg->storage().end()), "Registry must be empty");
+        ENTT_ASSERT(reg->template storage<entity_type>().free_list() == 0u, "Registry must be empty");
     }
     }
 
 
     /*! @brief Default move constructor. */
     /*! @brief Default move constructor. */

+ 5 - 0
test/entt/entity/snapshot.cpp

@@ -222,6 +222,11 @@ TEST(BasicSnapshotLoader, Constructors) {
     static_assert(std::is_move_assignable_v<entt::basic_snapshot_loader<entt::registry>>, "Move assignable type required");
     static_assert(std::is_move_assignable_v<entt::basic_snapshot_loader<entt::registry>>, "Move assignable type required");
 
 
     entt::registry registry;
     entt::registry registry;
+
+    // helps stress the check in the constructor
+    registry.emplace<int>(registry.create(), 0);
+    registry.clear();
+
     entt::basic_snapshot_loader loader{registry};
     entt::basic_snapshot_loader loader{registry};
     entt::basic_snapshot_loader other{std::move(loader)};
     entt::basic_snapshot_loader other{std::move(loader)};