From 7d43c4e7ad6b83a23516b26b4aebf74f398c251b Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 17 Oct 2017 23:13:04 +0200 Subject: Fix a bug in entity linking. --- src/world.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/world.cpp') diff --git a/src/world.cpp b/src/world.cpp index 06369f6..c18a7ab 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -192,7 +192,7 @@ void entity_t::link(world_t *world) for (int64_t y = 0; y < (int64_t)ysecs; y++) for (int64_t x = 0; x < (int64_t)xsecs; x++) { - sector_index_t index = sector_index_at(v2f_t(base[0] + x, base[1] + y)); + sector_index_t index = base + sector_index_t(x, y); sector_t *sector; sector = world->get_sector(index); @@ -202,8 +202,15 @@ void entity_t::link(world_t *world) void entity_t::unlink(void) { - for (sector_t *sector : parents) + for (sector_t *sector : parents) { + if (sector->ents.find(this) == sector->ents.end()) { + printf("entity_t::unlink: %p should belong to %p (%" PRIi64", %" PRIi64") but it doesn't\n", + this, sector, sector->index[0], sector->index[1]); + continue; + } + sector->ents.erase(sector->ents.find(this)); + } parents.clear(); parent_world = nullptr; -- cgit