Browse Source

Add fatal signal handler.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
7dae5aa367
3 changed files with 39 additions and 6 deletions
  1. +1
    -1
      include/common.hpp
  2. +1
    -1
      include/window.hpp
  3. +37
    -4
      src/main.cpp

+ 1
- 1
include/common.hpp View File

@@ -81,7 +81,7 @@ to reference the data beginning and end as a void* array, and
BINARY_SIZE(Test_dat)
to get its size in bytes.
*/
#ifdef ARCH_MAC
#if defined ARCH_MAC
// Use output from `xxd -i`
#define BINARY(sym) extern unsigned char sym[]; extern unsigned int sym##_len
#define BINARY_START(sym) ((const void*) sym)


+ 1
- 1
include/window.hpp View File

@@ -16,7 +16,7 @@
/** Remaps Ctrl to Cmd on Mac
Use this instead of GLFW_MOD_CONTROL, since Cmd should be used on Mac in place of Ctrl on Linux/Windows.
*/
#ifdef ARCH_MAC
#if defined ARCH_MAC
#define WINDOW_MOD_CTRL GLFW_MOD_SUPER
#define WINDOW_MOD_CTRL_NAME "Cmd"
#else


+ 37
- 4
src/main.cpp View File

@@ -14,21 +14,48 @@
#include "patch.hpp"
#include "ui.hpp"

#include <unistd.h>
#include <osdialog.h>
#include <unistd.h> // for getopt
#include <execinfo.h> // for backtrace and backtrace_symbols
#include <signal.h> // for signal

#ifdef ARCH_WIN

#if defined ARCH_WIN
#include <Windows.h>
#endif

using namespace rack;


static void fatalSignalHandler(int sig) {
// Only catch one signal
static bool caught = false;
if (caught)
exit(1);
caught = true;

const int bufferLen = 128;
void *buffer[bufferLen];
int size = backtrace(buffer, bufferLen);
char **strings = backtrace_symbols(buffer, size);

FATAL("Fatal signal %d. Backtrace:", sig);
FATAL("");
for (int i = 0; i < size; i++)
FATAL("%s", strings[i]);

osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack has crashed. See log.txt for details.");

free(strings);
exit(1);
}


int main(int argc, char *argv[]) {
#ifdef ARCH_WIN
#if defined ARCH_WIN
// Windows global mutex to prevent multiple instances
// Handle will be closed by Windows when the process ends
HANDLE instanceMutex = CreateMutex(NULL, true, app::NAME);
HANDLE instanceMutex = CreateMutex(NULL, true, app::APP_NAME);
if (GetLastError() == ERROR_ALREADY_EXISTS) {
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack is already running. Multiple Rack instances are not supported.");
exit(1);
@@ -63,6 +90,12 @@ int main(int argc, char *argv[]) {
// Initialize environment
asset::init(devMode);
logger::init(devMode);
// We can now install a signal handler and log the output
signal(SIGABRT, fatalSignalHandler);
signal(SIGFPE, fatalSignalHandler);
signal(SIGILL, fatalSignalHandler);
signal(SIGSEGV, fatalSignalHandler);
signal(SIGTERM, fatalSignalHandler);

// Log environment
INFO("%s v%s", app::APP_NAME, app::APP_VERSION);


Loading…
Cancel
Save