From 1bc2f230105ad6e1ee8d999ddc079cd85d244bf9 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 13 Nov 2015 12:58:36 +0100 Subject: [PATCH] try to cleanly destruct world this might still cause problems if there's circular references --- src/world/world.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/world/world.cpp b/src/world/world.cpp index b07d05a..738fa4a 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -340,7 +340,20 @@ World::World(const BlockTypeRegistry &types, const Config &config) } World::~World() { - + for (Entity &e : entities) { + e.Kill(); + } + std::size_t removed = 0; + do { + removed = 0; + for (auto e = entities.begin(), end = entities.end(); e != end; ++e) { + if (e->CanRemove()) { + e = RemoveEntity(e); + end = entities.end(); + ++removed; + } + } + } while (removed > 0 && !entities.empty()); } -- 2.39.2