From 82b35b5445d88d67c89c6547b24053d31dc35b9c Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 08:54:52 +0100 Subject: [PATCH] Fix stuff. Make sure different ways of aborting profiling work. --- gui/MainWindow.cpp | 12 ++++++++++++ gui/dialogs/SettingsDialog.ui | 8 +++++--- logic/profiler/BaseProfiler.cpp | 15 +++++++++++++++ logic/profiler/BaseProfiler.h | 4 ++++ logic/profiler/JProfiler.cpp | 11 ++++++++++- logic/profiler/JVisualVM.cpp | 12 +++++++++++- 6 files changed, 57 insertions(+), 5 deletions(-) diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 7c61ca9d..b28e753f 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -1256,6 +1256,7 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, dialog.setMaximum(0); dialog.setValue(0); dialog.setLabelText(tr("Waiting for profiler...")); + connect(&dialog, &QDialog::rejected, profilerInstance, &BaseProfiler::abortProfiling); dialog.show(); connect(profilerInstance, &BaseProfiler::readyToLaunch, [&dialog, this](const QString &message) { @@ -1270,6 +1271,17 @@ void MainWindow::launchInstance(BaseInstance *instance, AuthSessionPtr session, msg.exec(); proc->launch(); }); + connect(profilerInstance, &BaseProfiler::abortLaunch, [&dialog, this](const QString &message) + { + dialog.accept(); + QMessageBox msg; + msg.setText(tr("Couldn't start the profiler: %1").arg(message)); + msg.setWindowTitle(tr("Error")); + msg.setIcon(QMessageBox::Critical); + msg.addButton(QMessageBox::Ok); + msg.exec(); + proc->abort(); + }); profilerInstance->beginProfiling(proc); dialog.exec(); } diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 8d9a7f87..acf360a3 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -20,7 +20,7 @@ Settings - + :/icons/toolbar/settings:/icons/toolbar/settings @@ -33,7 +33,7 @@ QTabWidget::Rounded - 5 + 0 @@ -980,7 +980,9 @@ postExitCmdTextBox settingsTabs - + + + buttonBox diff --git a/logic/profiler/BaseProfiler.cpp b/logic/profiler/BaseProfiler.cpp index 4765c67d..1a377818 100644 --- a/logic/profiler/BaseProfiler.cpp +++ b/logic/profiler/BaseProfiler.cpp @@ -19,6 +19,21 @@ void BaseProfiler::beginProfiling(MinecraftProcess *process) beginProfilingImpl(process); } +void BaseProfiler::abortProfiling() +{ + abortProfiling(); +} + +void BaseProfiler::abortProfilingImpl() +{ + if (!m_profilerProcess) + { + return; + } + m_profilerProcess->terminate(); + m_profilerProcess->deleteLater(); +} + qint64 BaseProfiler::pid(QProcess *process) { #ifdef Q_OS_WIN diff --git a/logic/profiler/BaseProfiler.h b/logic/profiler/BaseProfiler.h index 4c5f63fc..e0d1d5f6 100644 --- a/logic/profiler/BaseProfiler.h +++ b/logic/profiler/BaseProfiler.h @@ -17,16 +17,20 @@ public: public slots: void beginProfiling(MinecraftProcess *process); + void abortProfiling(); protected: BaseInstance *m_instance; + QProcess *m_profilerProcess; virtual void beginProfilingImpl(MinecraftProcess *process) = 0; + virtual void abortProfilingImpl(); qint64 pid(QProcess *process); signals: void readyToLaunch(const QString &message); + void abortLaunch(const QString &message); }; class BaseProfilerFactory diff --git a/logic/profiler/JProfiler.cpp b/logic/profiler/JProfiler.cpp index cec614ae..34f927ce 100644 --- a/logic/profiler/JProfiler.cpp +++ b/logic/profiler/JProfiler.cpp @@ -22,7 +22,16 @@ void JProfiler::beginProfilingImpl(MinecraftProcess *process) .absoluteFilePath("bin/jpenable")); connect(profiler, &QProcess::started, [this, port]() { emit readyToLaunch(tr("Listening on port: %1").arg(port)); }); - connect(profiler, SIGNAL(finished(int)), profiler, SLOT(deleteLater())); + connect(profiler, + static_cast(&QProcess::finished), + [this](int exit, QProcess::ExitStatus status) + { + if (exit != 0 || status == QProcess::CrashExit) + { + emit abortLaunch(tr("Profiler aborted")); + } + m_profilerProcess->deleteLater(); + }); profiler->start(); } diff --git a/logic/profiler/JVisualVM.cpp b/logic/profiler/JVisualVM.cpp index 3850ff40..89098f73 100644 --- a/logic/profiler/JVisualVM.cpp +++ b/logic/profiler/JVisualVM.cpp @@ -19,8 +19,18 @@ void JVisualVM::beginProfilingImpl(MinecraftProcess *process) profiler->setProgram("jvisualvm"); connect(profiler, &QProcess::started, [this]() { emit readyToLaunch(tr("JVisualVM started")); }); - connect(profiler, SIGNAL(finished(int)), profiler, SLOT(deleteLater())); + connect(profiler, + static_cast(&QProcess::finished), + [this](int exit, QProcess::ExitStatus status) + { + if (exit != 0 || status == QProcess::CrashExit) + { + emit abortLaunch(tr("Profiler aborted")); + } + m_profilerProcess->deleteLater(); + }); profiler->start(); + m_profilerProcess = profiler; } void JVisualVMFactory::registerSettings(SettingsObject *settings)