From 855ece1d3b45c5deed5d92c295c89ac18b61183d Mon Sep 17 00:00:00 2001 From: nosoop Date: Tue, 20 Sep 2022 07:24:08 -0700 Subject: [PATCH] entitylump: Fix behavior of append (#1836) This change ensures that the iterator values used by `std::distance` is correct. Having the emplace within leads to the possibility of `m_Entities.begin()` being invalidated due to reallocations. --- core/logic/LumpManager.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/logic/LumpManager.cpp b/core/logic/LumpManager.cpp index d6b1eb7f..31649927 100644 --- a/core/logic/LumpManager.cpp +++ b/core/logic/LumpManager.cpp @@ -122,10 +122,8 @@ void EntityLumpManager::Insert(size_t index) { } size_t EntityLumpManager::Append() { - return std::distance( - m_Entities.begin(), - m_Entities.emplace(m_Entities.end(), std::make_shared()) - ); + auto it = m_Entities.emplace(m_Entities.end(), std::make_shared()); + return std::distance(m_Entities.begin(), it); } size_t EntityLumpManager::Length() {