trying to fix web crashes

This commit is contained in:
SamGondelman 2019-02-25 15:06:11 -08:00
parent b2e0067c08
commit f235d04601
2 changed files with 79 additions and 64 deletions

View file

@ -101,21 +101,15 @@ bool WebEntityRenderer::isTransparent() const {
} }
bool WebEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { bool WebEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const {
if (_contextPosition != entity->getWorldPosition()) { if (resultWithReadLock<bool>([&] {
return true; if (_webSurface && uvec2(getWindowSize(entity)) != toGlm(_webSurface->size())) {
} return true;
}
{
QSharedPointer<OffscreenQmlSurface> webSurface; if (_contextPosition != entity->getWorldPosition()) {
withReadLock([&] {
webSurface = _webSurface;
});
if (webSurface && uvec2(getWindowSize(entity)) != toGlm(webSurface->size())) {
return true; return true;
} }
}
if(resultWithReadLock<bool>([&] {
if (_color != entity->getColor()) { if (_color != entity->getColor()) {
return true; return true;
} }
@ -194,7 +188,7 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene
auto newContentType = getContentType(newSourceURL); auto newContentType = getContentType(newSourceURL);
ContentType currentContentType; ContentType currentContentType;
withReadLock([&] { withReadLock([&] {
urlChanged = _sourceURL != newSourceURL; urlChanged = newSourceURL.isEmpty() || newSourceURL != _tryingToBuildURL;
}); });
currentContentType = _contentType; currentContentType = _contentType;
@ -206,7 +200,6 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene
} }
} }
withWriteLock([&] { withWriteLock([&] {
_inputMode = entity->getInputMode(); _inputMode = entity->getInputMode();
_dpi = entity->getDPI(); _dpi = entity->getDPI();
@ -216,6 +209,8 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene
_billboardMode = entity->getBillboardMode(); _billboardMode = entity->getBillboardMode();
if (_contentType == ContentType::NoContent) { if (_contentType == ContentType::NoContent) {
_tryingToBuildURL = newSourceURL;
_sourceURL = newSourceURL;
return; return;
} }
@ -226,10 +221,12 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene
if (_webSurface) { if (_webSurface) {
if (_webSurface->getRootItem()) { if (_webSurface->getRootItem()) {
if (_contentType == ContentType::HtmlContent && urlChanged) { if (_contentType == ContentType::HtmlContent && _sourceURL != newSourceURL) {
_webSurface->getRootItem()->setProperty(URL_PROPERTY, newSourceURL); _webSurface->getRootItem()->setProperty(URL_PROPERTY, newSourceURL);
_sourceURL = newSourceURL;
} else if (_contentType != ContentType::HtmlContent) {
_sourceURL = newSourceURL;
} }
_sourceURL = newSourceURL;
{ {
auto scriptURL = entity->getScriptURL(); auto scriptURL = entity->getScriptURL();
@ -294,20 +291,21 @@ void WebEntityRenderer::doRender(RenderArgs* args) {
}); });
// Try to update the texture // Try to update the texture
{ OffscreenQmlSurface::TextureAndFence newTextureAndFence;
QSharedPointer<OffscreenQmlSurface> webSurface; bool newTextureAvailable = false;
withReadLock([&] { if (!resultWithReadLock<bool>([&] {
webSurface = _webSurface; if (!_webSurface) {
}); return false;
if (!webSurface) {
return;
} }
OffscreenQmlSurface::TextureAndFence newTextureAndFence; newTextureAvailable = _webSurface->fetchTexture(newTextureAndFence);
bool newTextureAvailable = webSurface->fetchTexture(newTextureAndFence); return true;
if (newTextureAvailable) { })) {
_texture->setExternalTexture(newTextureAndFence.first, newTextureAndFence.second); return;
} }
if (newTextureAvailable) {
_texture->setExternalTexture(newTextureAndFence.first, newTextureAndFence.second);
} }
static const glm::vec2 texMin(0.0f), texMax(1.0f), topLeft(-0.5f), bottomRight(0.5f); static const glm::vec2 texMin(0.0f), texMax(1.0f), topLeft(-0.5f), bottomRight(0.5f);
@ -351,6 +349,8 @@ void WebEntityRenderer::buildWebSurface(const EntityItemPointer& entity, const Q
_connections.push_back(QObject::connect(_webSurface.data(), &OffscreenQmlSurface::webEventReceived, this, [entityItemID](const QVariant& message) { _connections.push_back(QObject::connect(_webSurface.data(), &OffscreenQmlSurface::webEventReceived, this, [entityItemID](const QVariant& message) {
emit DependencyManager::get<EntityScriptingInterface>()->webEventReceived(entityItemID, message); emit DependencyManager::get<EntityScriptingInterface>()->webEventReceived(entityItemID, message);
})); }));
_tryingToBuildURL = newSourceURL;
} }
void WebEntityRenderer::destroyWebSurface() { void WebEntityRenderer::destroyWebSurface() {
@ -383,11 +383,16 @@ glm::vec2 WebEntityRenderer::getWindowSize(const TypedEntityPointer& entity) con
void WebEntityRenderer::hoverEnterEntity(const PointerEvent& event) { void WebEntityRenderer::hoverEnterEntity(const PointerEvent& event) {
if (_inputMode == WebInputMode::MOUSE) { if (_inputMode == WebInputMode::MOUSE) {
handlePointerEvent(event); handlePointerEvent(event);
} else if (_webSurface) { return;
PointerEvent webEvent = event;
webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi));
_webSurface->hoverBeginEvent(webEvent, _touchDevice);
} }
withReadLock([&] {
if (_webSurface) {
PointerEvent webEvent = event;
webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi));
_webSurface->hoverBeginEvent(webEvent, _touchDevice);
}
});
} }
void WebEntityRenderer::hoverLeaveEntity(const PointerEvent& event) { void WebEntityRenderer::hoverLeaveEntity(const PointerEvent& event) {
@ -398,34 +403,39 @@ void WebEntityRenderer::hoverLeaveEntity(const PointerEvent& event) {
// QML onReleased is only triggered if a click has happened first. We need to send this "fake" mouse move event to properly trigger an onExited. // QML onReleased is only triggered if a click has happened first. We need to send this "fake" mouse move event to properly trigger an onExited.
PointerEvent endMoveEvent(PointerEvent::Move, event.getID()); PointerEvent endMoveEvent(PointerEvent::Move, event.getID());
handlePointerEvent(endMoveEvent); handlePointerEvent(endMoveEvent);
} else if (_webSurface) {
PointerEvent webEvent = event;
webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi));
_webSurface->hoverEndEvent(webEvent, _touchDevice);
}
}
void WebEntityRenderer::handlePointerEvent(const PointerEvent& event) {
if (_inputMode == WebInputMode::TOUCH) {
handlePointerEventAsTouch(event);
} else {
handlePointerEventAsMouse(event);
}
}
void WebEntityRenderer::handlePointerEventAsTouch(const PointerEvent& event) {
if (_webSurface) {
PointerEvent webEvent = event;
webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi));
_webSurface->handlePointerEvent(webEvent, _touchDevice);
}
}
void WebEntityRenderer::handlePointerEventAsMouse(const PointerEvent& event) {
if (!_webSurface) {
return; return;
} }
withReadLock([&] {
if (_webSurface) {
PointerEvent webEvent = event;
webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi));
_webSurface->hoverEndEvent(webEvent, _touchDevice);
}
});
}
void WebEntityRenderer::handlePointerEvent(const PointerEvent& event) {
withReadLock([&] {
if (!_webSurface) {
return;
}
if (_inputMode == WebInputMode::TOUCH) {
handlePointerEventAsTouch(event);
} else {
handlePointerEventAsMouse(event);
}
});
}
void WebEntityRenderer::handlePointerEventAsTouch(const PointerEvent& event) {
PointerEvent webEvent = event;
webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi));
_webSurface->handlePointerEvent(webEvent, _touchDevice);
}
void WebEntityRenderer::handlePointerEventAsMouse(const PointerEvent& event) {
glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi);
QPointF windowPoint(windowPos.x, windowPos.y); QPointF windowPoint(windowPos.x, windowPos.y);
@ -459,16 +469,20 @@ void WebEntityRenderer::handlePointerEventAsMouse(const PointerEvent& event) {
} }
void WebEntityRenderer::setProxyWindow(QWindow* proxyWindow) { void WebEntityRenderer::setProxyWindow(QWindow* proxyWindow) {
if (_webSurface) { withReadLock([&] {
_webSurface->setProxyWindow(proxyWindow); if (_webSurface) {
} _webSurface->setProxyWindow(proxyWindow);
}
});
} }
QObject* WebEntityRenderer::getEventHandler() { QObject* WebEntityRenderer::getEventHandler() {
if (!_webSurface) { return resultWithReadLock<QObject*>([&]() -> QObject* {
return nullptr; if (!_webSurface) {
} return nullptr;
return _webSurface->getEventHandler(); }
return _webSurface->getEventHandler();
});
} }
void WebEntityRenderer::emitScriptEvent(const QVariant& message) { void WebEntityRenderer::emitScriptEvent(const QVariant& message) {

View file

@ -82,6 +82,7 @@ private:
QSharedPointer<OffscreenQmlSurface> _webSurface { nullptr }; QSharedPointer<OffscreenQmlSurface> _webSurface { nullptr };
bool _cachedWebSurface { false }; bool _cachedWebSurface { false };
gpu::TexturePointer _texture; gpu::TexturePointer _texture;
QString _tryingToBuildURL;
glm::u8vec3 _color; glm::u8vec3 _color;
float _alpha { 1.0f }; float _alpha { 1.0f };