Loose summons can be present in scene
Morrowind removes summons, if their leader disappears from scene (e.g. when he is disabled or teleported via scripting). From what I can tell, Morrowind just removes magic effects when it disables an actor or teleports him to an inactive cell. In OpenMW these summons become persistent in scene (since we do not update spells state for their leader). As a possible solution, we can use something like that:
// Note: addActor() still should use an old implementation of removeActor()
void Actors::removeActor (const MWWorld::Ptr& ptr)
{
PtrActorMap::iterator iter = mActors.find(ptr);
if(iter != mActors.end())
{
delete iter->second;
mActors.erase(iter);
// Recursive summons cleanup
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
std::map<CreatureStats::SummonKey, int>& creatureMap = stats.getSummonedCreatureMap();
for (const auto& creature : creatureMap)
cleanupSummonedCreature(stats, creature.second);
creatureMap.clear();
}
}
Unfortunately, it removes summons during cell change since our current approach to teleport actor between cells is the "remove an old actor and spawn and new one".
Edited by Andrei Kortunov