diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 87da8e6aa1..7763c3fb0b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1785,14 +1785,23 @@ void Application::cleanupBeforeQuit() { DependencyManager::destroy(); DependencyManager::destroy(); - // shutdown render engine - _main3DScene = nullptr; - _renderEngine = nullptr; - qCDebug(interfaceapp) << "Application::cleanupBeforeQuit() complete"; } Application::~Application() { + // remove avatars from physics engine + DependencyManager::get()->clearOtherAvatars(); + VectorOfMotionStates motionStates; + DependencyManager::get()->getObjectsToRemoveFromPhysics(motionStates); + _physicsEngine->removeObjects(motionStates); + DependencyManager::get()->deleteAllAvatars(); + + _physicsEngine->setCharacterController(nullptr); + + // shutdown render engine + _main3DScene = nullptr; + _renderEngine = nullptr; + DependencyManager::destroy(); _entityClipboard->eraseAllOctreeElements(); @@ -1804,14 +1813,6 @@ Application::~Application() { _octreeProcessor.terminate(); _entityEditSender.terminate(); - _physicsEngine->setCharacterController(nullptr); - - // remove avatars from physics engine - DependencyManager::get()->clearOtherAvatars(); - VectorOfMotionStates motionStates; - DependencyManager::get()->getObjectsToRemoveFromPhysics(motionStates); - _physicsEngine->removeObjects(motionStates); - DependencyManager::get()->deleteAllAvatars(); DependencyManager::destroy(); DependencyManager::destroy(); diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index ec47bcd0fe..585776b395 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -344,14 +344,18 @@ void AvatarManager::processAvatarDataPacket(QSharedPointer mess const render::ScenePointer& scene = qApp->getMain3DScene(); render::Transaction transaction; avatar->removeFromScene(avatar, scene, transaction); - scene->enqueueTransaction(transaction); + if (scene) { + scene->enqueueTransaction(transaction); + } } } else if (_shouldRender) { // very rare transition so we process the transaction immediately const render::ScenePointer& scene = qApp->getMain3DScene(); render::Transaction transaction; avatar->addToScene(avatar, scene, transaction); - scene->enqueueTransaction(transaction); + if (scene) { + scene->enqueueTransaction(transaction); + } } } }