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

This commit is contained in:
Michele Caini
2024-01-19 09:21:46 +01:00
parent 68688b2263
commit 353b3d19ee
2 changed files with 6 additions and 1 deletions

View File

@@ -164,7 +164,7 @@ public:
basic_snapshot_loader(registry_type &source) noexcept
: reg{&source} {
// 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. */

View File

@@ -227,6 +227,11 @@ TEST(BasicSnapshotLoader, Constructors) {
static_assert(std::is_move_assignable_v<entt::basic_snapshot_loader<entt::registry>>, "Move assignable type required");
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 other{std::move(loader)};