Skip to content

Commit

Permalink
linux: add simple crash handler that dumps stacktrace
Browse files Browse the repository at this point in the history
Since the Linux version seems much more unstable than the Windows one,
having more information where the crash occured will help with figuring
out where the problems are.

This commit adds a simple crash handler that dumps out the stacktrace,
it's only supported on Linux.
  • Loading branch information
brakhane committed Jan 13, 2025
1 parent 602117b commit dc315f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ else ()
)
set(LIB_DXCOMPILER "libdxcompiler.so")

# needed for proper names in crash stacktrace
set_target_properties(WickedEngineEditor
PROPERTIES
ENABLE_EXPORTS ON
)

endif ()

# Copy content to build folder:
Expand Down
33 changes: 32 additions & 1 deletion Editor/main_SDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

#include "icon.c"

#ifdef __linux__
# include <execinfo.h>
# include <signal.h>
#endif

using namespace std;

Editor editor;
Expand Down Expand Up @@ -92,8 +97,35 @@ void set_window_icon(SDL_Window *window) {
SDL_FreeSurface(icon);
}

#ifdef __linux__

void crash_handler(int sig)
{
void* buf[100];

size_t size = backtrace(buf, 100);
fprintf(stderr,
"\e[31m" // red
"The editor just crashed, sorry about that! If you make a bug report, please include the following information:\n\n"
"Signal: %i (%s)\n"
"Version: %s\nStacktrace:\n", sig, sigdescr_np(sig), wi::version::GetVersionString());
backtrace_symbols_fd(buf, size, STDERR_FILENO);
fprintf(stderr, "\e[m"); // back to normal
exit(1);
}

#endif

int main(int argc, char *argv[])
{

#ifdef __linux__
for (int sig : std::array{SIGABRT, SIGBUS, SIGILL, SIGFPE, SIGSEGV})
{
signal(sig, crash_handler);
}
#endif

wi::arguments::Parse(argc, argv);

sdl2::sdlsystem_ptr_t system = sdl2::make_sdlsystem(SDL_INIT_EVERYTHING | SDL_INIT_EVENTS);
Expand Down Expand Up @@ -121,7 +153,6 @@ int main(int argc, char *argv[])

width = std::max(100, width);
height = std::max(100, height);

sdl2::window_ptr_t window = sdl2::make_window(
"Wicked Editor",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
Expand Down

0 comments on commit dc315f4

Please sign in to comment.