From 3752d188c46c6eed5d190900fe6654642b3b8c63 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Thu, 25 Feb 2010 17:09:46 +0100 Subject: Protect against double initialization. --- src/declarative/qml/qdeclarativeengine.cpp | 24 +++++++++++++++++++----- src/declarative/qml/qdeclarativeengine_p.h | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 717857b..af75e98 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -336,6 +336,7 @@ void QDeclarativeEnginePrivate::clear(SimpleList &pss) } Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer); +Q_GLOBAL_STATIC(QSet, qmlEnginePluginsWithRegisteredTypes); void QDeclarativeEnginePrivate::init() { @@ -1621,19 +1622,32 @@ void QDeclarativeEngine::addImportPath(const QString& path) */ bool QDeclarativeEngine::importExtension(const QString &fileName, const QString &uri) { - QPluginLoader loader(fileName); + QFileInfo fileInfo(fileName); + const QString absoluteFilePath = fileInfo.absoluteFilePath(); + QPluginLoader loader(absoluteFilePath); if (QDeclarativeExtensionInterface *iface = qobject_cast(loader.instance())) { const QByteArray bytes = uri.toUtf8(); const char *moduleId = bytes.constData(); - QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this); - if (! d->importedPlugins.contains(fileName)) { - d->importedPlugins.insert(fileName); + // ### this code should probably be protected with a mutex. + if (! qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath)) { + // types should only be registered once (they're global). + + qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath); iface->registerTypes(moduleId); } - iface->initializeEngine(this, moduleId); + QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this); + + if (! d->initializedPlugins.contains(absoluteFilePath)) { + // things on the engine (eg. adding new global objects) have to be done for every engine. + + // protect against double initialization + d->initializedPlugins.insert(absoluteFilePath); + iface->initializeEngine(this, moduleId); + } + return true; } diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 6ef2f93..0359f98 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -267,7 +267,7 @@ public: QStringList environmentImportPath; - QSet importedPlugins; + QSet initializedPlugins; QString resolvePlugin(const QDir &dir, const QString &baseName, const QStringList &suffixes, -- cgit v0.12