protect against crash on invalid scene on shutdown

This commit is contained in:
Andrew Meadows 2017-04-17 11:51:10 -07:00
parent 014d7b8d8d
commit da55c96c4c
2 changed files with 19 additions and 14 deletions

View file

@ -1785,14 +1785,23 @@ void Application::cleanupBeforeQuit() {
DependencyManager::destroy<AudioClient>();
DependencyManager::destroy<AudioInjectorManager>();
// shutdown render engine
_main3DScene = nullptr;
_renderEngine = nullptr;
qCDebug(interfaceapp) << "Application::cleanupBeforeQuit() complete";
}
Application::~Application() {
// remove avatars from physics engine
DependencyManager::get<AvatarManager>()->clearOtherAvatars();
VectorOfMotionStates motionStates;
DependencyManager::get<AvatarManager>()->getObjectsToRemoveFromPhysics(motionStates);
_physicsEngine->removeObjects(motionStates);
DependencyManager::get<AvatarManager>()->deleteAllAvatars();
_physicsEngine->setCharacterController(nullptr);
// shutdown render engine
_main3DScene = nullptr;
_renderEngine = nullptr;
DependencyManager::destroy<Preferences>();
_entityClipboard->eraseAllOctreeElements();
@ -1804,14 +1813,6 @@ Application::~Application() {
_octreeProcessor.terminate();
_entityEditSender.terminate();
_physicsEngine->setCharacterController(nullptr);
// remove avatars from physics engine
DependencyManager::get<AvatarManager>()->clearOtherAvatars();
VectorOfMotionStates motionStates;
DependencyManager::get<AvatarManager>()->getObjectsToRemoveFromPhysics(motionStates);
_physicsEngine->removeObjects(motionStates);
DependencyManager::get<AvatarManager>()->deleteAllAvatars();
DependencyManager::destroy<AvatarManager>();
DependencyManager::destroy<AnimationCache>();

View file

@ -344,14 +344,18 @@ void AvatarManager::processAvatarDataPacket(QSharedPointer<ReceivedMessage> 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);
}
}
}
}