Skip to content

Commit f4ede8b

Browse files
committed
tools: clear stale runtime objects after destruction
1 parent ee8071d commit f4ede8b

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎samples/core/editors/level_editor/level_editor.lua‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,11 @@ function LevelEditor:set_placeable(placeable_type, name)
21692169
end
21702170

21712171
function LevelEditor:destroy(id)
2172-
self._objects[id]:destroy()
2172+
local object = self._objects[id]
2173+
assert(object ~= nil)
2174+
if UnitManager.alive(object:unit_id()) then
2175+
object:destroy()
2176+
end
21732177
self._objects[id] = nil
21742178
self._selection:remove(id)
21752179
self._selection:send()

‎tools/level_editor/level.vala‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ public class Level
278278
n += Sound.generate_destroy_commands(sb, object_ids[i:object_ids.length], _db);
279279
i += n == 0 ? 1 : n;
280280
}
281+
282+
// FIXME: Replace this full-database scan when undo uses full object snapshots.
283+
// Undoing creation currently removes child-set links before notifying us of destruction.
284+
GLib.HashTableIter<Guid?, GLib.HashTable<string, Value?>> iter = GLib.HashTableIter<Guid?, GLib.HashTable<string, Value?>>(_db._data);
285+
unowned Guid? id;
286+
while (iter.next(out id, null)) {
287+
if (_db.is_alive(id))
288+
continue;
289+
string type = _db.object_type(id);
290+
if (type == OBJECT_TYPE_UNIT || type == OBJECT_TYPE_SOUND_SOURCE)
291+
sb.append(LevelEditorApi.destroy(id));
292+
}
281293
}
282294

283295
public void generate_change_objects(StringBuilder sb, Guid?[] object_ids, bool respawn_units = false)

0 commit comments

Comments
 (0)