QmlDesigner: Fix crash in 3D import dialog close

If preview generation crashes for some reason, the puppet cleanup needs
to be done asynchronously instead of directly in the callback function,
as callback is triggered from cleaned up instances.

Also add an error text to the canvas where the preview should be shown
if it can't be generated due to crash.

Fixes: QDS-13012
Change-Id: I6196e5b395b056f6b3033ea4da3a0101ef8ea48f
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2024-06-17 13:31:29 +03:00
parent c9fd23ae12
commit e40720eda1
3 changed files with 15 additions and 2 deletions

View File

@@ -34,6 +34,12 @@ void Import3dCanvas::updateRenderImage(const QImage &img)
update();
}
void Import3dCanvas::displayError(const QString &error)
{
m_errorMsg = error;
update();
}
void Import3dCanvas::paintEvent([[maybe_unused]] QPaintEvent *e)
{
QWidget::paintEvent(e);
@@ -46,6 +52,9 @@ void Import3dCanvas::paintEvent([[maybe_unused]] QPaintEvent *e)
} else {
painter.drawImage(rect(), m_image, QRect(0, 0, m_image.width(), m_image.height()));
}
if (!m_errorMsg.isEmpty())
painter.drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignVCenter, m_errorMsg);
}
void Import3dCanvas::resizeEvent(QResizeEvent *)

View File

@@ -17,6 +17,7 @@ public:
Import3dCanvas(QWidget *parent);
void updateRenderImage(const QImage &img);
void displayError(const QString &error);
signals:
void requestImageUpdate();
@@ -32,6 +33,7 @@ protected:
private:
QImage m_image;
QPointF m_dragPos;
QString m_errorMsg;
};
} // namespace QmlDesigner

View File

@@ -1036,8 +1036,10 @@ Rectangle {
};
auto crashCallback = [&] {
addWarning("Preview process crashed.");
cleanupPreviewPuppet();
const QString errorMsg(tr("Preview generation process crashed."));
addWarning(errorMsg);
canvas()->displayError(errorMsg);
QTimer::singleShot(0, this, &ItemLibraryAssetImportDialog::cleanupPreviewPuppet);
};
m_connectionManager->setPreviewIconCallback(std::move(previewIconCallback));