fix various crashes-upon-exits

This commit is contained in:
Seth Alves 2018-06-19 10:13:48 -07:00
parent 0c9f0cbe03
commit dcebbada28
6 changed files with 36 additions and 17 deletions

View file

@ -814,6 +814,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
} }
// Tell the plugin manager about our statically linked plugins // Tell the plugin manager about our statically linked plugins
DependencyManager::set<PluginManager>();
auto pluginManager = PluginManager::getInstance(); auto pluginManager = PluginManager::getInstance();
pluginManager->setInputPluginProvider([] { return getInputPlugins(); }); pluginManager->setInputPluginProvider([] { return getInputPlugins(); });
pluginManager->setDisplayPluginProvider([] { return getDisplayPlugins(); }); pluginManager->setDisplayPluginProvider([] { return getDisplayPlugins(); });
@ -1375,6 +1376,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
initializeRenderEngine(); initializeRenderEngine();
qCDebug(interfaceapp, "Initialized Render Engine."); qCDebug(interfaceapp, "Initialized Render Engine.");
// Overlays need to exist before we set the ContextOverlayInterface dependency
_overlays.init(); // do this before scripts load
DependencyManager::set<ContextOverlayInterface>();
// Initialize the user interface and menu system // Initialize the user interface and menu system
// Needs to happen AFTER the render engine initialization to access its configuration // Needs to happen AFTER the render engine initialization to access its configuration
initializeUi(); initializeUi();
@ -1511,10 +1516,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
// allow you to move an entity around in your hand // allow you to move an entity around in your hand
_entityEditSender.setPacketsPerSecond(3000); // super high!! _entityEditSender.setPacketsPerSecond(3000); // super high!!
// Overlays need to exist before we set the ContextOverlayInterface dependency
_overlays.init(); // do this before scripts load
DependencyManager::set<ContextOverlayInterface>();
// Make sure we don't time out during slow operations at startup // Make sure we don't time out during slow operations at startup
updateHeartbeat(); updateHeartbeat();
@ -2552,12 +2553,18 @@ Application::~Application() {
_octreeProcessor.terminate(); _octreeProcessor.terminate();
_entityEditSender.terminate(); _entityEditSender.terminate();
if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
steamClient->shutdown();
}
DependencyManager::destroy<PluginManager>();
DependencyManager::destroy<CompositorHelper>(); // must be destroyed before the FramebufferCache
DependencyManager::destroy<AvatarManager>(); DependencyManager::destroy<AvatarManager>();
DependencyManager::destroy<AnimationCache>(); DependencyManager::destroy<AnimationCache>();
DependencyManager::destroy<FramebufferCache>(); DependencyManager::destroy<FramebufferCache>();
DependencyManager::destroy<TextureCache>(); DependencyManager::destroy<TextureCache>();
DependencyManager::destroy<ModelCache>(); DependencyManager::destroy<ModelCache>();
DependencyManager::destroy<GeometryCache>();
DependencyManager::destroy<ScriptCache>(); DependencyManager::destroy<ScriptCache>();
DependencyManager::destroy<SoundCache>(); DependencyManager::destroy<SoundCache>();
DependencyManager::destroy<OctreeStatsProvider>(); DependencyManager::destroy<OctreeStatsProvider>();
@ -2567,10 +2574,6 @@ Application::~Application() {
// remove the NodeList from the DependencyManager // remove the NodeList from the DependencyManager
DependencyManager::destroy<NodeList>(); DependencyManager::destroy<NodeList>();
if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
steamClient->shutdown();
}
#if 0 #if 0
ConnexionClient::getInstance().destroy(); ConnexionClient::getInstance().destroy();
#endif #endif
@ -2890,6 +2893,7 @@ void Application::initializeUi() {
auto compositorHelper = DependencyManager::get<CompositorHelper>(); auto compositorHelper = DependencyManager::get<CompositorHelper>();
connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, this, [=] { connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, this, [=] {
if (isHMDMode()) { if (isHMDMode()) {
auto compositorHelper = DependencyManager::get<CompositorHelper>(); // don't capture outer smartpointer
showCursor(compositorHelper->getAllowMouseCapture() ? showCursor(compositorHelper->getAllowMouseCapture() ?
Cursor::Manager::lookupIcon(_preferredCursor.get()) : Cursor::Manager::lookupIcon(_preferredCursor.get()) :
Cursor::Icon::SYSTEM); Cursor::Icon::SYSTEM);

View file

@ -139,7 +139,10 @@ void Application::paintGL() {
frame->frameIndex = _renderFrameCount; frame->frameIndex = _renderFrameCount;
frame->framebuffer = finalFramebuffer; frame->framebuffer = finalFramebuffer;
frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer) { frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer) {
DependencyManager::get<FramebufferCache>()->releaseFramebuffer(framebuffer); auto frameBufferCache = DependencyManager::get<FramebufferCache>();
if (frameBufferCache) {
frameBufferCache->releaseFramebuffer(framebuffer);
}
}; };
// deliver final scene rendering commands to the display plugin // deliver final scene rendering commands to the display plugin
{ {

View file

@ -50,6 +50,8 @@ ApplicationOverlay::~ApplicationOverlay() {
geometryCache->releaseID(_magnifierBorder); geometryCache->releaseID(_magnifierBorder);
geometryCache->releaseID(_qmlGeometryId); geometryCache->releaseID(_qmlGeometryId);
} }
DependencyManager::destroy<GeometryCache>();
} }
// Renders the overlays either to a texture or to the screen // Renders the overlays either to a texture or to the screen

View file

@ -39,8 +39,13 @@ ResourceManager::ResourceManager(bool atpSupportEnabled) : _atpSupportEnabled(at
} }
ResourceManager::~ResourceManager() { ResourceManager::~ResourceManager() {
_thread.terminate(); if (_thread.isRunning()) {
_thread.wait(); _thread.quit();
static const auto MAX_RESOURCE_MANAGER_THREAD_QUITTING_TIME = 0.5 * MSECS_PER_SECOND;
if (!_thread.wait(MAX_RESOURCE_MANAGER_THREAD_QUITTING_TIME)) {
_thread.terminate();
}
}
} }
void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) { void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) {

View file

@ -40,9 +40,8 @@ void PluginManager::setInputPluginSettingsPersister(const InputPluginSettingsPer
_inputSettingsPersister = persister; _inputSettingsPersister = persister;
} }
PluginManager* PluginManager::getInstance() { PluginManagerPointer PluginManager::getInstance() {
static PluginManager _manager; return DependencyManager::get<PluginManager>();
return &_manager;
} }
QString getPluginNameFromMetaData(QJsonObject object) { QString getPluginNameFromMetaData(QJsonObject object) {

View file

@ -9,11 +9,17 @@
#include <QObject> #include <QObject>
#include <DependencyManager.h>
#include "Forward.h" #include "Forward.h"
class PluginManager : public QObject {
class PluginManager;
using PluginManagerPointer = QSharedPointer<PluginManager>;
class PluginManager : public QObject, public Dependency {
public: public:
static PluginManager* getInstance(); static PluginManagerPointer getInstance();
PluginManager(); PluginManager();
const DisplayPluginList& getDisplayPlugins(); const DisplayPluginList& getDisplayPlugins();