fix app close crash, fix error on msvc

This commit is contained in:
Sen66
2026-03-01 21:49:49 +01:00
parent 552b45b16c
commit da312ccac6
4 changed files with 31 additions and 1 deletions

View File

@@ -165,6 +165,12 @@ RcxController::~RcxController() {
m_refreshWatcher->cancel();
m_refreshWatcher->waitForFinished();
}
m_snapshotProv.reset();
}
void RcxController::resetProvider() {
m_snapshotProv.reset();
}
RcxEditor* RcxController::primaryEditor() const {

View File

@@ -127,6 +127,7 @@ public:
void setEditorFont(const QString& fontName);
void setRefreshInterval(int ms);
void setCompactColumns(bool v);
void resetProvider();
// MCP bridge accessors
void setSuppressRefresh(bool v) { m_suppressRefresh = v; }

View File

@@ -109,7 +109,7 @@ static LONG WINAPI crashHandler(EXCEPTION_POINTERS* ep) {
SYSTEMTIME st;
GetLocalTime(&st);
wchar_t dumpPath[MAX_PATH];
_snwprintf(dumpPath, MAX_PATH,
_snwprintf_s(dumpPath, MAX_PATH,
L"%sreclass_crash_%04d%02d%02d_%02d%02d%02d.dmp",
exePath, st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute, st.wSecond);
@@ -1391,6 +1391,28 @@ static void buildEmptyStruct(NodeTree& tree, const QString& classKeyword = QStri
}
}
MainWindow::~MainWindow() {
/*
* When MainWindow is destroyed:
*
* 1. ~MainWindow() runs (our code — plugin DLLs still loaded)
* 2. MainWindow member variables are destroyed (m_pluginManager — unloads plugin DLLs)
* 3. QObject::~QObject() runs — destroys child widgets (QMdiSubWindow → RcxController → ~RcxController())
*
*/
// Disconnect all subwindow destroyed signals before members are torn down,
// so the lambdas capturing 'this' never fire on a half-destroyed object.
for (auto it = m_tabs.begin(); it != m_tabs.end(); ++it) {
disconnect(it.key(), &QObject::destroyed, this, nullptr);
// Release providers now while plugin DLLs are still loaded;
// if deferred to Qt child cleanup the DLL code may already be unloaded.
it->doc->provider.reset();
it->ctrl->resetProvider();
}
m_tabs.clear();
}
void MainWindow::newClass() {
project_new(QStringLiteral("class"));
}

View File

@@ -30,6 +30,7 @@ class MainWindow : public QMainWindow {
friend class McpBridge;
public:
explicit MainWindow(QWidget* parent = nullptr);
~MainWindow() override;
private slots:
void newClass();