Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/common/iflytek_ai_assistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include <QtConcurrent/QtConcurrentRun>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusInterface>

Check warning on line 12 in src/common/iflytek_ai_assistant.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 13 in src/common/iflytek_ai_assistant.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcess>

Check warning on line 14 in src/common/iflytek_ai_assistant.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QProcess> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCoreApplication>

Check warning on line 15 in src/common/iflytek_ai_assistant.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStandardPaths>

Check warning on line 16 in src/common/iflytek_ai_assistant.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStandardPaths> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QDBusInterface>

Check warning on line 18 in src/common/iflytek_ai_assistant.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusReply>
#include <QDBusObjectPath>
#include <QJsonDocument>
Expand Down Expand Up @@ -388,15 +389,28 @@
}
}

bool IflytekAiAssistant::appShuttingDown()
{
// 主线程进入 ~QCoreApplication(closingDown)或应用已析构后,dtk6log/事件派发
// 处于 teardown 状态,后台线程再走日志或排队回调会崩溃(BUG-378881/378901)
QCoreApplication *app = QCoreApplication::instance();
return app == nullptr || app->closingDown();
}

IflytekAiAssistant::CallStatus IflytekAiAssistant::copilotInstalled(const QSharedPointer<QDBusInterface> &copilot)
{
QDBusReply<QString> version = copilot->call("version");
if (version.isValid()) {
qInfo() << "current uos-ai version:" << version.value();
// 阻塞调用可能跨越整个应用退出过程(默认超时 25s),返回后须复查
if (!appShuttingDown()) {
qInfo() << "current uos-ai version:" << version.value();
}
return Enable;
}

qWarning() << "Query uos-ai installed faild! Maybe need install";
if (!appShuttingDown()) {
qWarning() << "Query uos-ai installed faild! Maybe need install";
}
return NotInstalled;
}

Expand All @@ -408,12 +422,16 @@
{
QDBusReply<bool> state = copilot->call("isCopilotEnabled");
if (state.isValid()) {
qDebug() << "current uos-ai user exp state:" << state.value();
if (!appShuttingDown()) {
qDebug() << "current uos-ai user exp state:" << state.value();
}
return state.value() ? Enable : NoUserAgreement;
}

// NOTE: Adapt old version, if dbus interface not valid, assume the user agreement agreed.
qWarning() << "Query uos-ai user exp state failed!" << state.error().message();
if (!appShuttingDown()) {
qWarning() << "Query uos-ai user exp state failed!" << state.error().message();
}
return Enable;
}

Expand All @@ -437,13 +455,23 @@
static std::once_flag kAiFlag;
std::call_once(kAiFlag, [this]() {
QtConcurrent::run([this]() {
// 任务可能排队到应用退出期才被线程池执行
if (appShuttingDown()) {
return;
}
// If call dbus interface success, the uos-ai backend process started.
auto copilot = QSharedPointer<QDBusInterface>::create(kCopilotService, kCopilotPath, kCopilotInterface);
CallStatus status = IflytekAiAssistant::copilotInstalled(copilot);
if (Enable == status) {
status = IflytekAiAssistant::isCopilotEnabled(copilot);
}

// 阻塞 D-Bus 期间应用可能已进入析构(主线程卡在 ~QCoreApplication
// 的 QThreadPool::waitForDone 等本任务收尾),此时打日志/排队回调即崩溃
if (appShuttingDown()) {
return;
}

qInfo() << QString("backend uos-ai status: %1(%2)").arg(Enable == status).arg(status);

// call on non-gui thread, so queued connection.
Expand Down
3 changes: 3 additions & 0 deletions src/common/iflytek_ai_assistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class IflytekAiAssistant : public QObject
static CallStatus isCopilotEnabled(const QSharedPointer<QDBusInterface> &copilot);
static CallStatus launchCopilotChat(const QSharedPointer<QDBusInterface> &copilot);

/// BUG-378881/378901: 应用 teardown 期间为 true,后台探测线程此时不得打日志/排队回调
static bool appShuttingDown();

static QString copilotService();

bool m_inited{false};
Expand Down
16 changes: 10 additions & 6 deletions src/editor/editwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ EditWrapper::EditWrapper(Window *window, QWidget *parent)
EditWrapper::~EditWrapper()
{
qDebug() << "EditWrapper destructor";
// 必须在 delete m_pTextEdit 之前清理 m_pWaringNotices,避免 DMessageManager
// 持有 m_pTextEdit 悬空指针导致 use-after-free(bug 378881)。
// 此前 bug 78042 的崩溃根因是 delete m_pWaringNotices 位于 m_pTextEdit 之后,
// DMessageManager 在处理消息移除时访问已释放的 m_pTextEdit;将删除顺序
// 调整为先 m_pWaringNotices 后 m_pTextEdit 即可同时避免两个问题。
if (m_pWaringNotices != nullptr) {
disconnect(m_pWaringNotices);
delete m_pWaringNotices;
m_pWaringNotices = nullptr;
}
if (m_pTextEdit != nullptr) {
qDebug() << "EditWrapper destructor, m_pTextEdit not nullptr";
disconnect(m_pTextEdit);
Expand All @@ -150,12 +160,6 @@ EditWrapper::~EditWrapper()
delete m_pBottomBar;
m_pBottomBar = nullptr;
}
//delete 之后,如果出现文件被修改,需要重新加载弹框,之后,点击标签关闭,闪退问题 78042 ut002764
// if (m_pWaringNotices != nullptr) {
// disconnect(m_pWaringNotices);
// delete m_pWaringNotices;
// m_pWaringNotices = nullptr;
// }
qDebug() << "EditWrapper destructor exit";
}

Expand Down
Loading