Browse Source

UI: Add crash report dialog

This crash report dialog is mostly just for the windows crash handling
code.  If a crash occurs, the user will be able to view the crash report
and post it on the forums or give it to a developer for debugging
purposes.
jp9000 10 years ago
parent
commit
824c7b02c9
4 changed files with 89 additions and 0 deletions
  1. 2 0
      obs/CMakeLists.txt
  2. 52 0
      obs/crash-report.cpp
  3. 18 0
      obs/crash-report.hpp
  4. 17 0
      obs/obs-app.cpp

+ 2 - 0
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

+ 52 - 0
obs/crash-report.cpp

@@ -0,0 +1,52 @@
+#include "crash-report.hpp"
+#include <QApplication>
+#include <QFontDatabase>
+#include <QPlainTextEdit>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QClipboard>
+#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());
+}

+ 18 - 0
obs/crash-report.hpp

@@ -0,0 +1,18 @@
+#pragma once
+
+#include <QDialog>
+
+class QPlainTextEdit;
+
+class OBSCrashReport : public QDialog {
+	Q_OBJECT
+
+	QPlainTextEdit *textBox;
+
+public:
+	OBSCrashReport(QWidget *parent, const char *text);
+
+public slots:
+	void ExitClicked();
+	void CopyClicked();
+};

+ 17 - 0
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 <fstream>
@@ -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;