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.
This commit is contained in:
jp9000 2015-01-02 17:11:27 -08:00
parent e3068ed985
commit 824c7b02c9
4 changed files with 89 additions and 0 deletions

View file

@ -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
obs/crash-report.cpp Normal file
View file

@ -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
obs/crash-report.hpp Normal file
View file

@ -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();
};

View file

@ -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;