mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:56:44 +02:00
Attempting to fix threading issues with web entities
This commit is contained in:
parent
a0097bcff8
commit
3b7e8a69b5
5 changed files with 35 additions and 28 deletions
|
@ -341,6 +341,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
_domainConnectionRefusals(QList<QString>()),
|
_domainConnectionRefusals(QList<QString>()),
|
||||||
_maxOctreePPS(maxOctreePacketsPerSecond.get())
|
_maxOctreePPS(maxOctreePacketsPerSecond.get())
|
||||||
{
|
{
|
||||||
|
setInstance(this);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
installNativeEventFilter(&MyNativeEventFilter::getInstance());
|
installNativeEventFilter(&MyNativeEventFilter::getInstance());
|
||||||
#endif
|
#endif
|
||||||
|
@ -4694,7 +4695,3 @@ qreal Application::getDevicePixelRatio() {
|
||||||
return _window ? _window->windowHandle()->devicePixelRatio() : 1.0;
|
return _window ? _window->windowHandle()->devicePixelRatio() : 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AbstractViewStateInterface* AbstractViewStateInterface::instance() {
|
|
||||||
return qApp;
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,13 +33,15 @@ EntityItem* RenderableWebEntityItem::factory(const EntityItemID& entityID, const
|
||||||
|
|
||||||
RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||||
WebEntityItem(entityItemID, properties) {
|
WebEntityItem(entityItemID, properties) {
|
||||||
|
qDebug() << "Created web entity " << getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderableWebEntityItem::~RenderableWebEntityItem() {
|
RenderableWebEntityItem::~RenderableWebEntityItem() {
|
||||||
if (_webSurface) {
|
if (_webSurface) {
|
||||||
_webSurface->pause();
|
_webSurface->pause();
|
||||||
_webSurface->disconnect(_connection);
|
_webSurface->disconnect(_connection);
|
||||||
// After the disconnect, ensure that we have the latest
|
// After the disconnect, ensure that we have the latest texture by acquiring the
|
||||||
|
// lock used when updating the _texture value
|
||||||
_textureLock.lock();
|
_textureLock.lock();
|
||||||
_textureLock.unlock();
|
_textureLock.unlock();
|
||||||
// The lifetime of the QML surface MUST be managed by the main thread
|
// The lifetime of the QML surface MUST be managed by the main thread
|
||||||
|
@ -55,6 +57,7 @@ RenderableWebEntityItem::~RenderableWebEntityItem() {
|
||||||
webSurface->deleteLater();
|
webSurface->deleteLater();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
qDebug() << "Destroyed web entity " << getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::render(RenderArgs* args) {
|
void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
|
@ -66,7 +69,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
|
_webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/"));
|
||||||
_webSurface->load("WebEntity.qml");
|
_webSurface->load("WebEntity.qml");
|
||||||
_webSurface->resume();
|
_webSurface->resume();
|
||||||
updateQmlSourceUrl();
|
_webSurface->getRootItem()->setProperty("url", _sourceUrl);
|
||||||
_connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) {
|
_connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) {
|
||||||
_webSurface->lockTexture(textureId);
|
_webSurface->lockTexture(textureId);
|
||||||
assert(!glGetError());
|
assert(!glGetError());
|
||||||
|
@ -135,24 +138,10 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
void RenderableWebEntityItem::setSourceUrl(const QString& value) {
|
void RenderableWebEntityItem::setSourceUrl(const QString& value) {
|
||||||
if (_sourceUrl != value) {
|
if (_sourceUrl != value) {
|
||||||
_sourceUrl = value;
|
_sourceUrl = value;
|
||||||
AbstractViewStateInterface::instance()->postLambdaEvent([this] {
|
if (_webSurface) {
|
||||||
// Update the offscreen display
|
AbstractViewStateInterface::instance()->postLambdaEvent([this] {
|
||||||
updateQmlSourceUrl();
|
_webSurface->getRootItem()->setProperty("url", _sourceUrl);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::updateQmlSourceUrl() {
|
|
||||||
if (!_webSurface) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto webView = _webSurface->getRootItem();
|
|
||||||
if (!webView) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!_sourceUrl.isEmpty()) {
|
|
||||||
webView->setProperty("url", _sourceUrl);
|
|
||||||
} else {
|
|
||||||
webView->setProperty("url", QVariant());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,9 +26,7 @@ public:
|
||||||
virtual void setSourceUrl(const QString& value);
|
virtual void setSourceUrl(const QString& value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateQmlSourceUrl();
|
OffscreenQmlSurface* _webSurface{ nullptr };
|
||||||
|
|
||||||
OffscreenQmlSurface* _webSurface;
|
|
||||||
QMetaObject::Connection _connection;
|
QMetaObject::Connection _connection;
|
||||||
uint32_t _texture{ 0 };
|
uint32_t _texture{ 0 };
|
||||||
QMutex _textureLock;
|
QMutex _textureLock;
|
||||||
|
|
20
libraries/render-utils/src/AbstractViewStateInterface.cpp
Normal file
20
libraries/render-utils/src/AbstractViewStateInterface.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// Created by Bradley Austin Davis 2015/05/13
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "AbstractViewStateInterface.h"
|
||||||
|
|
||||||
|
static AbstractViewStateInterface* INSTANCE{nullptr};
|
||||||
|
|
||||||
|
AbstractViewStateInterface* AbstractViewStateInterface::instance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractViewStateInterface::setInstance(AbstractViewStateInterface* instance) {
|
||||||
|
INSTANCE = instance;
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
class Transform;
|
class Transform;
|
||||||
class QThread;
|
class QThread;
|
||||||
class ViewFrustum;
|
class ViewFrustum;
|
||||||
|
@ -59,6 +61,7 @@ public:
|
||||||
virtual qreal getDevicePixelRatio() = 0;
|
virtual qreal getDevicePixelRatio() = 0;
|
||||||
|
|
||||||
static AbstractViewStateInterface* instance();
|
static AbstractViewStateInterface* instance();
|
||||||
|
static void setInstance(AbstractViewStateInterface* instance);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue