mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 11:50:39 +02:00
Still trying to address QML crashes
This commit is contained in:
parent
77705c5ffa
commit
0e9f8cc103
1 changed files with 52 additions and 33 deletions
|
@ -264,9 +264,6 @@ QNetworkAccessManager* QmlNetworkAccessManagerFactory::create(QObject* parent) {
|
|||
return new QmlNetworkAccessManager(parent);
|
||||
}
|
||||
|
||||
static QQmlEngine* globalEngine { nullptr };
|
||||
static size_t globalEngineRefCount { 0 };
|
||||
|
||||
QString getEventBridgeJavascript() {
|
||||
// FIXME: Refactor with similar code in RenderableWebEntityItem
|
||||
QString javaScriptToInject;
|
||||
|
@ -300,33 +297,26 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#define SINGLE_QML_ENGINE 0
|
||||
|
||||
QQmlEngine* acquireEngine(QQuickWindow* window) {
|
||||
Q_ASSERT(QThread::currentThread() == qApp->thread());
|
||||
if (QThread::currentThread() != qApp->thread()) {
|
||||
qCWarning(uiLogging) << "Cannot acquire QML engine on any thread but the main thread";
|
||||
}
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [] {
|
||||
qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect");
|
||||
});
|
||||
#if SINGLE_QML_ENGINE
|
||||
static QQmlEngine* globalEngine{ nullptr };
|
||||
static size_t globalEngineRefCount{ 0 };
|
||||
#endif
|
||||
|
||||
if (!globalEngine) {
|
||||
Q_ASSERT(0 == globalEngineRefCount);
|
||||
globalEngine = new QQmlEngine();
|
||||
globalEngine->setNetworkAccessManagerFactory(new QmlNetworkAccessManagerFactory);
|
||||
|
||||
auto importList = globalEngine->importPathList();
|
||||
void initializeQmlEngine(QQmlEngine* engine, QQuickWindow* window) {
|
||||
engine->setNetworkAccessManagerFactory(new QmlNetworkAccessManagerFactory);
|
||||
auto importList = engine->importPathList();
|
||||
importList.insert(importList.begin(), PathUtils::resourcesPath());
|
||||
globalEngine->setImportPathList(importList);
|
||||
engine->setImportPathList(importList);
|
||||
for (const auto& path : importList) {
|
||||
qDebug() << path;
|
||||
}
|
||||
|
||||
if (!globalEngine->incubationController()) {
|
||||
globalEngine->setIncubationController(window->incubationController());
|
||||
if (!engine->incubationController()) {
|
||||
engine->setIncubationController(window->incubationController());
|
||||
}
|
||||
auto rootContext = globalEngine->rootContext();
|
||||
auto rootContext = engine->rootContext();
|
||||
rootContext->setContextProperty("GL", ::getGLContextData());
|
||||
rootContext->setContextProperty("urlHandler", new UrlHandler());
|
||||
rootContext->setContextProperty("resourceDirectoryUrl", QUrl::fromLocalFile(PathUtils::resourcesPath()));
|
||||
|
@ -341,17 +331,46 @@ QQmlEngine* acquireEngine(QQuickWindow* window) {
|
|||
rootContext->setContextProperty("HFTabletWebEngineProfile", new HFTabletWebEngineProfile(rootContext));
|
||||
}
|
||||
|
||||
QQmlEngine* acquireEngine(QQuickWindow* window) {
|
||||
Q_ASSERT(QThread::currentThread() == qApp->thread());
|
||||
|
||||
QQmlEngine* result = nullptr;
|
||||
if (QThread::currentThread() != qApp->thread()) {
|
||||
qCWarning(uiLogging) << "Cannot acquire QML engine on any thread but the main thread";
|
||||
}
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [] {
|
||||
qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect");
|
||||
});
|
||||
|
||||
|
||||
#if SINGLE_QML_ENGINE
|
||||
if (!globalEngine) {
|
||||
Q_ASSERT(0 == globalEngineRefCount);
|
||||
globalEngine = new QQmlEngine();
|
||||
initializeQmlEngine(result, window);
|
||||
++globalEngineRefCount;
|
||||
return globalEngine;
|
||||
}
|
||||
result = globalEngine;
|
||||
#else
|
||||
result = new QQmlEngine();
|
||||
initializeQmlEngine(result, window);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void releaseEngine() {
|
||||
void releaseEngine(QQmlEngine* engine) {
|
||||
Q_ASSERT(QThread::currentThread() == qApp->thread());
|
||||
#if SINGLE_QML_ENGINE
|
||||
Q_ASSERT(0 != globalEngineRefCount);
|
||||
if (0 == --globalEngineRefCount) {
|
||||
globalEngine->deleteLater();
|
||||
globalEngine = nullptr;
|
||||
}
|
||||
#else
|
||||
engine->deleteLater();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OffscreenQmlSurface::cleanup() {
|
||||
|
@ -456,11 +475,11 @@ OffscreenQmlSurface::~OffscreenQmlSurface() {
|
|||
QObject::disconnect(qApp);
|
||||
|
||||
cleanup();
|
||||
|
||||
auto engine = _qmlContext->engine();
|
||||
_canvas->deleteLater();
|
||||
_rootItem->deleteLater();
|
||||
_quickWindow->deleteLater();
|
||||
releaseEngine();
|
||||
releaseEngine(engine);
|
||||
}
|
||||
|
||||
void OffscreenQmlSurface::onAboutToQuit() {
|
||||
|
|
Loading…
Reference in a new issue