From fc18c75557f53f9d9b8481152e34378a5f9ebe11 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 31 May 2024 19:07:51 +0300 Subject: [PATCH] Fix ecs bug when finalizing removal of detached entity in the last row of the old table --- libs/ecs/source/container.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/ecs/source/container.cpp b/libs/ecs/source/container.cpp index 45ca53a3..c97953de 100644 --- a/libs/ecs/source/container.cpp +++ b/libs/ecs/source/container.cpp @@ -89,10 +89,14 @@ namespace psemek::ecs { // Swap with the last row in that table auto table_entity_handles = table.entity_handles(); - table.swap_rows(row, table_entity_handles.size() - 1); + auto last_row = table_entity_handles.size() - 1; + if (row != last_row) + { + table.swap_rows(row, last_row); + auto swap_handle = table_entity_handles[row]; + entities[swap_handle.id].row = row; + } table.pop_row(); - auto swap_handle = table_entity_handles[row]; - entities[swap_handle.id].row = row; } void container::finalize_iteration(detail::table & table)