don't invalidate iterator before changing non-deleted asset indices

This commit is contained in:
Nick Fisher
2023-12-17 13:11:16 +08:00
parent de3cc00059
commit b899ce544e

View File

@@ -517,22 +517,26 @@ namespace polyvox
Log("Couldn't find asset under specified entity id."); Log("Couldn't find asset under specified entity id.");
return; return;
} }
SceneAsset &sceneAsset = _assets[pos->second]; auto assetIndex = pos->second;
SceneAsset &sceneAsset = _assets[assetIndex];
Log("Removing entity %d at asset index %d", entityId, assetIndex);
_entityIdLookup.erase(entityId);
for(auto entityPos : _entityIdLookup) { for(auto entityPos : _entityIdLookup) {
if(entityPos.second > pos->second) { if(entityPos.second > pos->second) {
_entityIdLookup[entityPos.first] = entityPos.second-1; _entityIdLookup[entityPos.first] = entityPos.second-1;
} }
} }
_entityIdLookup.erase(entityId);
_scene->removeEntities(sceneAsset.asset->getEntities(), _scene->removeEntities(sceneAsset.asset->getEntities(),
sceneAsset.asset->getEntityCount()); sceneAsset.asset->getEntityCount());
auto lightCount =sceneAsset.asset->getLightEntityCount();
_scene->removeEntities(sceneAsset.asset->getLightEntities(), if(lightCount > 0) { _scene->removeEntities(sceneAsset.asset->getLightEntities(),
sceneAsset.asset->getLightEntityCount()); sceneAsset.asset->getLightEntityCount());
}
_assetLoader->destroyAsset(sceneAsset.asset); _assetLoader->destroyAsset(sceneAsset.asset);