From d5c6e981262c4a3d49f9d2bf6bf75b11d244e5ad Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Tue, 24 Mar 2026 01:52:44 +1100 Subject: [PATCH] fix: null check qmlEngine() in CUtils::saveItem qmlEngine(this) can return nullptr during engine shutdown, causing a null pointer dereference in the async callback. --- plugin/src/Caelestia/cutils.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugin/src/Caelestia/cutils.cpp b/plugin/src/Caelestia/cutils.cpp index 6e3bfa99..b6ec33a8 100644 --- a/plugin/src/Caelestia/cutils.cpp +++ b/plugin/src/Caelestia/cutils.cpp @@ -75,13 +75,20 @@ void CUtils::saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, Q QObject::connect(watcher, &QFutureWatcher::finished, this, [=]() { if (watcher->result()) { if (onSaved.isCallable()) { - onSaved.call( - { QJSValue(path.toLocalFile()), engine->toScriptValue(QVariant::fromValue(path)) }); + QJSValueList args = { QJSValue(path.toLocalFile()) }; + if (engine) { + args << engine->toScriptValue(QVariant::fromValue(path)); + } + onSaved.call(args); } } else { qWarning() << "CUtils::saveItem: failed to save" << path; if (onFailed.isCallable()) { - onFailed.call({ engine->toScriptValue(QVariant::fromValue(path)) }); + if (engine) { + onFailed.call({ engine->toScriptValue(QVariant::fromValue(path)) }); + } else { + onFailed.call(); + } } } watcher->deleteLater();