From: Daniel Karbach Date: Fri, 13 Nov 2015 11:58:36 +0000 (+0100) Subject: try to cleanly destruct world X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=1bc2f230105ad6e1ee8d999ddc079cd85d244bf9;hp=fa73e3600dee78063ab95e1903172ab339dcd4bd;p=blank.git try to cleanly destruct world this might still cause problems if there's circular references --- 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()); }