Merge pull request #10254 from druiz17/tablet-crash

Potential fix for crash for TabletScriptingInterface::getTabletWindow
This commit is contained in:
Seth Alves 2017-04-24 12:35:04 -07:00 committed by GitHub
commit aea8b020d2
4 changed files with 23 additions and 3 deletions

View file

@ -669,6 +669,7 @@ void ScriptEngine::init() {
globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE)));
registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
qScriptRegisterMetaType(this, tabletToScriptValue, tabletFromScriptValue);
registerGlobalObject("Assets", &_assetScriptingInterface);
registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());

View file

@ -21,6 +21,15 @@
#include <InfoView.h>
#include "SoundEffect.h"
QScriptValue tabletToScriptValue(QScriptEngine* engine, TabletProxy* const &in) {
return engine->newQObject(in, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater | QScriptEngine::ExcludeChildObjects);
}
void tabletFromScriptValue(const QScriptValue& value, TabletProxy* &out) {
out = qobject_cast<TabletProxy*>(value.toQObject());
}
TabletScriptingInterface::TabletScriptingInterface() {
qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect");
}
@ -41,7 +50,7 @@ QObject* TabletScriptingInterface::getSystemToolbarProxy() {
}
}
QObject* TabletScriptingInterface::getTablet(const QString& tabletId) {
TabletProxy* TabletScriptingInterface::getTablet(const QString& tabletId) {
std::lock_guard<std::mutex> guard(_mutex);

View file

@ -14,7 +14,9 @@
#include <QObject>
#include <QVariant>
#include <QScriptValue>
#include <QtScript/QScriptValue>
#include <QScriptEngine>
#include <QScriptValueIterator>
#include <QQuickItem>
#include <QUuid>
@ -45,7 +47,7 @@ public:
* @param name {String} tablet name
* @return {TabletProxy} tablet instance
*/
Q_INVOKABLE QObject* getTablet(const QString& tabletId);
Q_INVOKABLE TabletProxy* getTablet(const QString& tabletId);
void setToolbarMode(bool toolbarMode);
@ -259,6 +261,11 @@ protected:
bool _landscape { false };
};
Q_DECLARE_METATYPE(TabletProxy*);
QScriptValue tabletToScriptValue(QScriptEngine* engine, TabletProxy* const &in);
void tabletFromScriptValue(const QScriptValue& value, TabletProxy* &out);
/**jsdoc
* @class TabletButtonProxy
* @property uuid {QUuid} READ_ONLY: uniquely identifies this button

View file

@ -96,6 +96,9 @@ void OffscreenUi::create(QOpenGLContext* context) {
rootContext->setContextProperty("OffscreenUi", this);
rootContext->setContextProperty("offscreenFlags", offscreenFlags = new OffscreenFlags());
rootContext->setContextProperty("fileDialogHelper", new FileDialogHelper());
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
TabletProxy* tablet = tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system");
rootContext->engine()->setObjectOwnership(tablet, QQmlEngine::CppOwnership);
}
void OffscreenUi::show(const QUrl& url, const QString& name, std::function<void(QQmlContext*, QObject*)> f) {