mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:49:24 +02:00
Make Application destructor work when terminating early
This commit is contained in:
parent
c748064d0a
commit
a4e79ff806
1 changed files with 48 additions and 29 deletions
|
@ -2897,43 +2897,59 @@ void Application::cleanupBeforeQuit() {
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
// remove avatars from physics engine
|
// remove avatars from physics engine
|
||||||
auto avatarManager = DependencyManager::get<AvatarManager>();
|
if (auto avatarManager = DependencyManager::get<AvatarManager>()) {
|
||||||
avatarManager->clearOtherAvatars();
|
// AvatarManager may not yet exist in case of an early exit
|
||||||
auto myCharacterController = getMyAvatar()->getCharacterController();
|
|
||||||
myCharacterController->clearDetailedMotionStates();
|
|
||||||
|
|
||||||
PhysicsEngine::Transaction transaction;
|
avatarManager->clearOtherAvatars();
|
||||||
avatarManager->buildPhysicsTransaction(transaction);
|
auto myCharacterController = getMyAvatar()->getCharacterController();
|
||||||
_physicsEngine->processTransaction(transaction);
|
myCharacterController->clearDetailedMotionStates();
|
||||||
avatarManager->handleProcessedPhysicsTransaction(transaction);
|
|
||||||
avatarManager->deleteAllAvatars();
|
|
||||||
|
|
||||||
_physicsEngine->setCharacterController(nullptr);
|
PhysicsEngine::Transaction transaction;
|
||||||
|
avatarManager->buildPhysicsTransaction(transaction);
|
||||||
|
_physicsEngine->processTransaction(transaction);
|
||||||
|
avatarManager->handleProcessedPhysicsTransaction(transaction);
|
||||||
|
avatarManager->deleteAllAvatars();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_physicsEngine) {
|
||||||
|
_physicsEngine->setCharacterController(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// the _shapeManager should have zero references
|
// the _shapeManager should have zero references
|
||||||
_shapeManager.collectGarbage();
|
_shapeManager.collectGarbage();
|
||||||
assert(_shapeManager.getNumShapes() == 0);
|
assert(_shapeManager.getNumShapes() == 0);
|
||||||
|
|
||||||
// shutdown graphics engine
|
if (_graphicsEngine) {
|
||||||
_graphicsEngine->shutdown();
|
// shutdown graphics engine
|
||||||
|
_graphicsEngine->shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
_gameWorkload.shutdown();
|
_gameWorkload.shutdown();
|
||||||
|
|
||||||
DependencyManager::destroy<Preferences>();
|
DependencyManager::destroy<Preferences>();
|
||||||
PlatformHelper::shutdown();
|
PlatformHelper::shutdown();
|
||||||
|
|
||||||
_entityClipboard->eraseAllOctreeElements();
|
if (_entityClipboard) {
|
||||||
_entityClipboard.reset();
|
_entityClipboard->eraseAllOctreeElements();
|
||||||
|
_entityClipboard.reset();
|
||||||
_octreeProcessor->terminate();
|
|
||||||
_entityEditSender->terminate();
|
|
||||||
|
|
||||||
if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
|
|
||||||
steamClient->shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto oculusPlatform = PluginManager::getInstance()->getOculusPlatformPlugin()) {
|
if (_octreeProcessor) {
|
||||||
oculusPlatform->shutdown();
|
_octreeProcessor->terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_entityEditSender) {
|
||||||
|
_entityEditSender->terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto pluginManager = PluginManager::getInstance()) {
|
||||||
|
if (auto steamClient = pluginManager->getSteamClientPlugin()) {
|
||||||
|
steamClient->shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto oculusPlatform = pluginManager->getOculusPlatformPlugin()) {
|
||||||
|
oculusPlatform->shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DependencyManager::destroy<PluginManager>();
|
DependencyManager::destroy<PluginManager>();
|
||||||
|
@ -2961,7 +2977,9 @@ Application::~Application() {
|
||||||
DependencyManager::destroy<GeometryCache>();
|
DependencyManager::destroy<GeometryCache>();
|
||||||
DependencyManager::destroy<ScreenshareScriptingInterface>();
|
DependencyManager::destroy<ScreenshareScriptingInterface>();
|
||||||
|
|
||||||
DependencyManager::get<ResourceManager>()->cleanup();
|
if (auto resourceManager = DependencyManager::get<ResourceManager>()) {
|
||||||
|
resourceManager->cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
// remove the NodeList from the DependencyManager
|
// remove the NodeList from the DependencyManager
|
||||||
DependencyManager::destroy<NodeList>();
|
DependencyManager::destroy<NodeList>();
|
||||||
|
@ -2975,13 +2993,14 @@ Application::~Application() {
|
||||||
_window->deleteLater();
|
_window->deleteLater();
|
||||||
|
|
||||||
// make sure that the quit event has finished sending before we take the application down
|
// make sure that the quit event has finished sending before we take the application down
|
||||||
auto closeEventSender = DependencyManager::get<CloseEventSender>();
|
if (auto closeEventSender = DependencyManager::get<CloseEventSender>()) {
|
||||||
while (!closeEventSender->hasFinishedQuitEvent() && !closeEventSender->hasTimedOutQuitEvent()) {
|
while (!closeEventSender->hasFinishedQuitEvent() && !closeEventSender->hasTimedOutQuitEvent()) {
|
||||||
// sleep a little so we're not spinning at 100%
|
// sleep a little so we're not spinning at 100%
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
}
|
||||||
|
// quit the thread used by the closure event sender
|
||||||
|
closeEventSender->thread()->quit();
|
||||||
}
|
}
|
||||||
// quit the thread used by the closure event sender
|
|
||||||
closeEventSender->thread()->quit();
|
|
||||||
|
|
||||||
// Can't log to file past this point, FileLogger about to be deleted
|
// Can't log to file past this point, FileLogger about to be deleted
|
||||||
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
|
Loading…
Reference in a new issue