diff options
Diffstat (limited to 'source/creator/creator.c')
-rw-r--r-- | source/creator/creator.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c index 1f6f4d85f43..7e9e433598b 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -43,6 +43,8 @@ #include <stdlib.h> #include <stddef.h> #include <string.h> +#include <signal.h> + /* This little block needed for linking to Blender... */ @@ -124,6 +126,8 @@ #include "libmv-capi.h" #endif +static int no_handler = 0; + // from buildinfo.c #ifdef BUILD_DATE extern char build_date[]; @@ -321,6 +325,32 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data) double PIL_check_seconds_timer(void); +static void segmentation_handler(int UNUSED(sig)) +{ + char fname[256]; + + if (!G.main->name[0]) { + BLI_make_file_string("/", fname, BLI_temporary_dir(), "crash.blend"); + } + else { + sprintf(fname, "%s.crash.blend", G.main->name); + } + + BKE_undo_save(fname); + + /*induce a real crash*/ + signal(SIGSEGV, SIG_DFL); + *(int*)NULL = 0; +} + +static int nocrashhandler(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data)) +{ + no_handler = 1; + + return 0; +} + + static int end_arguments(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data)) { return -1; @@ -1091,7 +1121,8 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) BLI_argsAdd(ba, 2, "-con", "--start-console", "\n\tStart with the console window open (ignored if -b is set)", start_with_console, NULL); BLI_argsAdd(ba, 2, "-R", NULL, "\n\tRegister .blend extension, then exit (Windows only)", register_extension, NULL); BLI_argsAdd(ba, 2, "-r", NULL, "\n\tSilently register .blend extension, then exit (Windows only)", register_extension, ba); - + BLI_argsAdd(ba, 2, "--no_crash_handler", NULL, "disable crash handler", nocrashhandler, NULL); + /* third pass: disabling things and forcing settings */ BLI_argsAddCase(ba, 3, "-nojoystick", 1, NULL, 0, "\n\tDisable joystick support", no_joystick, syshandle); BLI_argsAddCase(ba, 3, "-noglsl", 1, NULL, 0, "\n\tDisable GLSL shading", no_glsl, NULL); @@ -1116,7 +1147,6 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) BLI_argsAdd(ba, 4, "-F", "--render-format", format_doc, set_image_type, C); BLI_argsAdd(ba, 4, "-t", "--threads", "<threads>\n\tUse amount of <threads> for rendering in background\n\t[1-" STRINGIFY(BLENDER_MAX_THREADS) "], 0 for systems processor count.", set_threads, NULL); BLI_argsAdd(ba, 4, "-x", "--use-extension", "<bool>\n\tSet option to add the file extension to the end of the file", set_extension, C); - } #ifdef WITH_PYTHON_MODULE @@ -1198,6 +1228,11 @@ int main(int argc, const char **argv) BLI_argsParse(ba, 1, NULL, NULL); + if (!no_handler) { + signal(SIGSEGV, segmentation_handler); + //signal(SIGFPE, segmentation_handler); + } + #if defined(WITH_PYTHON_MODULE) || defined(WITH_HEADLESS) G.background= 1; /* python module mode ALWAYS runs in background mode (for now) */ #else |