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)