From 5676246d751f2b1f5fe64e1ef91037b2e1acc86c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 13 Jul 2015 15:26:52 -0700 Subject: [PATCH] fix the lingering model parts sometimes left behind when switching domains --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 7 +++++-- .../entities-renderer/src/RenderableModelEntityItem.cpp | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 11d24c6d9d..6be891e147 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -93,16 +93,18 @@ void EntityTreeRenderer::clear() { foreach (const EntityItemID& entityID, _entityScripts.keys()) { checkAndCallUnload(entityID); } - OctreeRenderer::clear(); _entityScripts.clear(); auto scene = _viewState->getMain3DScene(); render::PendingChanges pendingChanges; + foreach(auto entity, _entitiesInScene) { entity->removeFromScene(entity, scene, pendingChanges); } scene->enqueuePendingChanges(pendingChanges); _entitiesInScene.clear(); + + OctreeRenderer::clear(); } void EntityTreeRenderer::init() { @@ -1003,7 +1005,7 @@ void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) { checkAndCallUnload(entityID); } _entityScripts.remove(entityID); - + // here's where we remove the entity payload from the scene if (_entitiesInScene.contains(entityID)) { auto entity = _entitiesInScene.take(entityID); @@ -1164,6 +1166,7 @@ void EntityTreeRenderer::updateEntityRenderStatus(bool shouldRenderEntities) { } else { _entityIDsLastInScene = _entitiesInScene.keys(); for (auto entityID : _entityIDsLastInScene) { + // FIXME - is this really right? do we want to do the deletingEntity() code or just remove from the scene. deletingEntity(entityID); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 85b7bafc78..2deb34d1f8 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -189,6 +189,7 @@ void makeEntityItemStatusGetters(RenderableModelEntityItem* entity, render::Item bool RenderableModelEntityItem::addToScene(EntityItemPointer self, std::shared_ptr scene, render::PendingChanges& pendingChanges) { + _myMetaItem = scene->allocateID(); auto renderData = RenderableModelEntityItemMeta::Pointer(new RenderableModelEntityItemMeta(self)); @@ -199,7 +200,10 @@ bool RenderableModelEntityItem::addToScene(EntityItemPointer self, std::shared_p if (_model) { render::Item::Status::Getters statusGetters; makeEntityItemStatusGetters(this, statusGetters); - return _model->addToScene(scene, pendingChanges, statusGetters); + + // note: we don't care if the model fails to add items, we always added our meta item and therefore we return + // true so that the system knows our meta item is in the scene! + _model->addToScene(scene, pendingChanges, statusGetters); } return true;