Skip to content

Commit 1dcd7aa

Browse files
committed
storage: fix an issue with in-place delete after the changes for reentrant destructors
1 parent 8b0008a commit 1dcd7aa

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/entt/entity/storage.hpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ class basic_storage: public basic_sparse_set<Entity, typename stl::allocator_tra
255255
return it;
256256
}
257257

258-
void shrink_to_size() {
259-
const auto from = (base_type::size() + traits_type::page_size - 1u) / traits_type::page_size;
258+
void shrink_to_size(const bool assume_empty = false) {
259+
const auto from = assume_empty ? 0u : (base_type::size() + traits_type::page_size - 1u) / traits_type::page_size;
260260
allocator_type allocator{get_allocator()};
261261

262262
for(auto pos = from, last = payload.size(); pos < last; ++pos) {
@@ -447,7 +447,8 @@ class basic_storage: public basic_sparse_set<Entity, typename stl::allocator_tra
447447
// NOLINTNEXTLINE(bugprone-exception-escape)
448448
~basic_storage() override {
449449
pop_all();
450-
shrink_to_size();
450+
// skip tombstones when shrinking
451+
shrink_to_size(true);
451452
}
452453

453454
/**

0 commit comments

Comments
 (0)