diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt index 14cc0376c..4353f77f2 100644 --- a/obs/CMakeLists.txt +++ b/obs/CMakeLists.txt @@ -105,6 +105,7 @@ set(obs_SOURCES properties-view.cpp volume-control.cpp adv-audio-control.cpp + crash-report.cpp qt-wrappers.cpp) set(obs_HEADERS @@ -129,6 +130,7 @@ set(obs_HEADERS volume-control.hpp adv-audio-control.hpp qt-display.hpp + crash-report.hpp qt-wrappers.hpp) set(obs_UI diff --git a/obs/crash-report.cpp b/obs/crash-report.cpp new file mode 100644 index 000000000..6a94692e7 --- /dev/null +++ b/obs/crash-report.cpp @@ -0,0 +1,52 @@ +#include "crash-report.hpp" +#include +#include +#include +#include +#include +#include +#include +#include "qt-wrappers.hpp" + +OBSCrashReport::OBSCrashReport(QWidget *parent, const char *text) + : QDialog(parent) +{ + QPushButton *copyButton = new QPushButton; + copyButton->setText("Copy crash log"); + + QPushButton *exitButton = new QPushButton; + exitButton->setText("Exit"); + + textBox = new QPlainTextEdit; + textBox->setPlainText(QT_UTF8(text)); + textBox->setLineWrapMode(QPlainTextEdit::NoWrap); + textBox->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(copyButton); + buttonLayout->addWidget(exitButton); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(textBox); + mainLayout->addItem(buttonLayout); + + setLayout(mainLayout); + + QWidget::connect(copyButton, SIGNAL(clicked()), + this, SLOT(CopyClicked())); + QWidget::connect(exitButton, SIGNAL(clicked()), + this, SLOT(ExitClicked())); + + resize(800, 600); + setWindowTitle("Oops, OBS has crashed!"); +} + +void OBSCrashReport::ExitClicked() +{ + exit(-1); +} + +void OBSCrashReport::CopyClicked() +{ + QApplication::clipboard()->setText(textBox->toPlainText()); +} diff --git a/obs/crash-report.hpp b/obs/crash-report.hpp new file mode 100644 index 000000000..32f590e77 --- /dev/null +++ b/obs/crash-report.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +class QPlainTextEdit; + +class OBSCrashReport : public QDialog { + Q_OBJECT + + QPlainTextEdit *textBox; + +public: + OBSCrashReport(QWidget *parent, const char *text); + +public slots: + void ExitClicked(); + void CopyClicked(); +}; diff --git a/obs/obs-app.cpp b/obs/obs-app.cpp index fd11e776a..22bb2241b 100644 --- a/obs/obs-app.cpp +++ b/obs/obs-app.cpp @@ -30,6 +30,7 @@ #include "obs-app.hpp" #include "window-basic-main.hpp" #include "window-license-agreement.hpp" +#include "crash-report.hpp" #include "platform.hpp" #include @@ -559,12 +560,28 @@ static int run_program(fstream &logFile, int argc, char *argv[]) return ret; } +#define MAX_CRASH_REPORT_SIZE (50 * 1024) + +static void main_crash_handler(const char *format, va_list args, void *param) +{ + char *test = new char[MAX_CRASH_REPORT_SIZE]; + + vsnprintf(test, MAX_CRASH_REPORT_SIZE, format, args); + + OBSCrashReport crashReport(nullptr, test); + crashReport.exec(); + exit(-1); + + UNUSED_PARAMETER(param); +} + int main(int argc, char *argv[]) { #ifndef WIN32 signal(SIGPIPE, SIG_IGN); #endif + base_set_crash_handler(main_crash_handler, nullptr); base_get_log_handler(&def_log_handler, nullptr); fstream logFile;