mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 14:10:40 +02:00
Fix for crash bug in web entities
Guard against nullptrs in RenderableWebEntitItem and WebEntityAPIHelper. These pointers can go null if the webEntity is deleted on the main thread. Also, the backing offscreen qml surface can be destroyed if the webEntity has not been rendered for 30 seconds due to frustum culling.
This commit is contained in:
parent
769a29332c
commit
a79485f8c2
1 changed files with 42 additions and 28 deletions
|
@ -58,9 +58,13 @@ void WebEntityAPIHelper::emitWebEvent(const QVariant& message) {
|
||||||
} else {
|
} else {
|
||||||
// special case to handle raising and lowering the virtual keyboard
|
// special case to handle raising and lowering the virtual keyboard
|
||||||
if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD" && _renderableWebEntityItem) {
|
if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD" && _renderableWebEntityItem) {
|
||||||
|
if (_renderableWebEntityItem) {
|
||||||
_renderableWebEntityItem->setKeyboardRaised(true);
|
_renderableWebEntityItem->setKeyboardRaised(true);
|
||||||
|
}
|
||||||
} else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD" && _renderableWebEntityItem) {
|
} else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD" && _renderableWebEntityItem) {
|
||||||
|
if (_renderableWebEntityItem) {
|
||||||
_renderableWebEntityItem->setKeyboardRaised(false);
|
_renderableWebEntityItem->setKeyboardRaised(false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
emit webEventReceived(message);
|
emit webEventReceived(message);
|
||||||
}
|
}
|
||||||
|
@ -388,6 +392,8 @@ static bool equals(const QByteArray& byteArray, const uint8_t* ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
|
void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
|
||||||
|
auto eventHandler = getEventHandler();
|
||||||
|
if (eventHandler) {
|
||||||
auto utf8Key = key.toUtf8();
|
auto utf8Key = key.toUtf8();
|
||||||
|
|
||||||
int scanCode = (int)utf8Key[0];
|
int scanCode = (int)utf8Key[0];
|
||||||
|
@ -411,12 +417,15 @@ void RenderableWebEntityItem::synthesizeKeyPress(QString key) {
|
||||||
|
|
||||||
QKeyEvent* pressEvent = new QKeyEvent(QEvent::KeyPress, scanCode, Qt::NoModifier, keyString);
|
QKeyEvent* pressEvent = new QKeyEvent(QEvent::KeyPress, scanCode, Qt::NoModifier, keyString);
|
||||||
QKeyEvent* releaseEvent = new QKeyEvent(QEvent::KeyRelease, scanCode, Qt::NoModifier, keyString);
|
QKeyEvent* releaseEvent = new QKeyEvent(QEvent::KeyRelease, scanCode, Qt::NoModifier, keyString);
|
||||||
QCoreApplication::postEvent(getEventHandler(), pressEvent);
|
QCoreApplication::postEvent(eventHandler, pressEvent);
|
||||||
QCoreApplication::postEvent(getEventHandler(), releaseEvent);
|
QCoreApplication::postEvent(eventHandler, releaseEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::emitScriptEvent(const QVariant& message) {
|
void RenderableWebEntityItem::emitScriptEvent(const QVariant& message) {
|
||||||
|
if (_webEntityAPIHelper) {
|
||||||
_webEntityAPIHelper->emitScriptEvent(message);
|
_webEntityAPIHelper->emitScriptEvent(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::setKeyboardRaised(bool raised) {
|
void RenderableWebEntityItem::setKeyboardRaised(bool raised) {
|
||||||
|
@ -424,5 +433,10 @@ void RenderableWebEntityItem::setKeyboardRaised(bool raised) {
|
||||||
// raise the keyboard only while in HMD mode and it's being requested.
|
// raise the keyboard only while in HMD mode and it's being requested.
|
||||||
bool value = AbstractViewStateInterface::instance()->isHMDMode() && raised;
|
bool value = AbstractViewStateInterface::instance()->isHMDMode() && raised;
|
||||||
|
|
||||||
_webSurface->getRootItem()->setProperty("keyboardRaised", QVariant(value));
|
if (_webSurface) {
|
||||||
|
auto rootItem = _webSurface->getRootItem();
|
||||||
|
if (rootItem) {
|
||||||
|
rootItem->setProperty("keyboardRaised", QVariant(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue