On Saturday, 23 March 2024 at 23:59:18 UTC, Liam McGillivray
wrote:
I replaced `destroy(unit)` with `map.deleteUnit(unit)`, and it
solved the problem.
Nevermind. It turns out this was because the call to the Unit
destructor was missing in `Map.deleteUnit`. The segfault happens
whenever a unit is destroyed.
In this case, how should I handle safe destruction of units,
given that there are multiple arrays that contain references to
it?
- Just call the unit destructor directly. The unit destructor
will call functions in `Map` & `Faction` to delist the unit from
it's arrays.
- Call a function in `Map` which will delist the unit from
`allUnits`, call a function in it's faction to delist it, and
then call the unit's destructor.
- Just call the units destructor, which will be rather plain.
`Map` & `Faction` will have functions that frequently go over
it's list of units, and delete any null references found.