Jelajahi Sumber

world: remove unit from map

Fixes: #217
Daniele Bartolini 1 tahun lalu
induk
melakukan
dc6d8f0178
2 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 1 0
      docs/changelog.rst
  2. 2 1
      src/world/script_world.cpp

+ 1 - 0
docs/changelog.rst

@@ -25,6 +25,7 @@ Changelog
 * Lua API: added ``SceneGraph.owner()``, ``SceneGraph.first_child()`` and ``SceneGraph.next_sibling()``.
 * Data Compiler: .mesh resource can now have shared geometries between nodes.
 * Data Compiler: .unit resources have now the ability to add/remove inherited children or to override them by adding, removing or modifying their components.
+* Fixed destroying units with a script component.
 
 0.53.0 --- 30 Nov 2024
 ----------------------

+ 2 - 1
src/world/script_world.cpp

@@ -95,7 +95,7 @@ namespace script_world
 
 	void destroy(ScriptWorld &sw, UnitId unit, ScriptInstance /*i*/)
 	{
-		CE_ASSERT(hash_map::has(sw._map, unit), "Unit does not have script component");
+		CE_ASSERT(hash_map::has(sw._map, unit), "Unit %u does not have script component", unit._idx);
 
 		const u32 unit_i    = hash_map::get(sw._map, unit, UINT32_MAX);
 		const u32 last_i    = array::size(sw._data) - 1;
@@ -121,6 +121,7 @@ namespace script_world
 
 		sw._data[unit_i] = sw._data[last_i];
 		hash_map::set(sw._map, last_u, unit_i);
+		hash_map::remove(sw._map, unit);
 		array::pop_back(sw._data);
 	}