fix for occasional crash when deleting web entity

This commit is contained in:
Anthony J. Thibault 2016-09-07 10:59:16 -07:00
parent dc0d0c2d5c
commit 41e0b8732f
3 changed files with 13 additions and 10 deletions

View file

@ -41,8 +41,6 @@ Item {
property string newUrl: ""
profile: desktop.browserProfile
webChannel.registeredObjects: [eventBridgeWrapper]
Component.onCompleted: {
@ -51,6 +49,8 @@ Item {
root.javaScriptConsoleMessage.connect(function(level, message, lineNumber, sourceID) {
console.log("Web Entity JS message: " + sourceID + " " + lineNumber + " " + message);
});
root.profile.httpUserAgent = "Mozilla/5.0 Chrome (HighFidelityInterface)"
}
// FIXME hack to get the URL with the auth token included. Remove when we move to Qt 5.6
@ -96,6 +96,7 @@ Item {
}
onNewViewRequested:{
// desktop is not defined for web-entities
if (desktop) {
var component = Qt.createComponent("../Browser.qml");
var newWindow = component.createObject(desktop);

View file

@ -81,18 +81,20 @@ RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemI
_touchDevice.setName("RenderableWebEntityItemTouchDevice");
_touchDevice.setMaximumTouchPoints(4);
_webEntityAPIHelper.setPtr(this);
_webEntityAPIHelper.moveToThread(qApp->thread());
_webEntityAPIHelper = new WebEntityAPIHelper;
_webEntityAPIHelper->setPtr(this);
_webEntityAPIHelper->moveToThread(qApp->thread());
// forward web events to EntityScriptingInterface
auto entities = DependencyManager::get<EntityScriptingInterface>();
QObject::connect(&_webEntityAPIHelper, &WebEntityAPIHelper::webEventReceived, [=](const QVariant& message) {
QObject::connect(_webEntityAPIHelper, &WebEntityAPIHelper::webEventReceived, [=](const QVariant& message) {
emit entities->webEventReceived(entityItemID, message);
});
}
RenderableWebEntityItem::~RenderableWebEntityItem() {
_webEntityAPIHelper.setPtr(nullptr);
_webEntityAPIHelper->setPtr(nullptr);
_webEntityAPIHelper->deleteLater();
destroyWebSurface();
qDebug() << "Destroyed web entity " << getID();
}
@ -113,10 +115,10 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) {
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/controls/"));
_webSurface->load("WebView.qml");
_webSurface->resume();
_webSurface->getRootItem()->setProperty("eventBridge", QVariant::fromValue(&_webEntityAPIHelper));
_webSurface->getRootItem()->setProperty("eventBridge", QVariant::fromValue(_webEntityAPIHelper));
_webSurface->getRootItem()->setProperty("url", _sourceUrl);
_webSurface->getRootContext()->setContextProperty("desktop", QVariant());
_webSurface->getRootContext()->setContextProperty("webEntity", &_webEntityAPIHelper);
_webSurface->getRootContext()->setContextProperty("webEntity", _webEntityAPIHelper);
_connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) {
_texture = textureId;
});
@ -402,7 +404,7 @@ void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
}
void RenderableWebEntityItem::emitScriptEvent(const QVariant& message) {
_webEntityAPIHelper.emitScriptEvent(message);
_webEntityAPIHelper->emitScriptEvent(message);
}
void RenderableWebEntityItem::setKeyboardRaised(bool raised) {

View file

@ -86,7 +86,7 @@ private:
QTouchEvent _lastTouchEvent { QEvent::TouchUpdate };
uint64_t _lastRenderTime{ 0 };
QTouchDevice _touchDevice;
WebEntityAPIHelper _webEntityAPIHelper;
WebEntityAPIHelper* _webEntityAPIHelper;
QMetaObject::Connection _mousePressConnection;
QMetaObject::Connection _mouseReleaseConnection;