diff options
Diffstat (limited to 'ZAPD/Main.cpp')
| -rw-r--r-- | ZAPD/Main.cpp | 91 |
1 files changed, 22 insertions, 69 deletions
diff --git a/ZAPD/Main.cpp b/ZAPD/Main.cpp index 531edc0..321ba01 100644 --- a/ZAPD/Main.cpp +++ b/ZAPD/Main.cpp @@ -10,22 +10,12 @@ #include "ZFile.h" #include "ZTexture.h" -#if !defined(_MSC_VER) && !defined(__CYGWIN__) -#include <csignal> -#include <cstdlib> -#include <ctime> -#include <cxxabi.h> // for __cxa_demangle -#include <dlfcn.h> // for dladdr -#include <execinfo.h> -#include <unistd.h> -#endif +#include "CrashHandler.h" #include <string> #include <string_view> #include "tinyxml2.h" -extern const char gBuildHash[]; - bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode); @@ -33,63 +23,9 @@ void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const f void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath); void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath); -#if !defined(_MSC_VER) && !defined(__CYGWIN__) -#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof(arr[0])) -void ErrorHandler(int sig) -{ - void* array[4096]; - const size_t nMaxFrames = sizeof(array) / sizeof(array[0]); - size_t size = backtrace(array, nMaxFrames); - char** symbols = backtrace_symbols(array, nMaxFrames); - - fprintf(stderr, "\nZAPD crashed. (Signal: %i)\n", sig); - - // Feel free to add more crash messages. - const char* crashEasterEgg[] = { - "\tYou've met with a terrible fate, haven't you?", - "\tSEA BEARS FOAM. SLEEP BEARS DREAMS. \n\tBOTH END IN THE SAME WAY: CRASSSH!", - "\tZAPD has fallen and cannot get up.", - }; - - srand(time(nullptr)); - auto easterIndex = rand() % ARRAY_COUNT(crashEasterEgg); - - fprintf(stderr, "\n%s\n\n", crashEasterEgg[easterIndex]); - - fprintf(stderr, "Traceback:\n"); - for (size_t i = 1; i < size; i++) - { - Dl_info info; - uint32_t gotAddress = dladdr(array[i], &info); - std::string functionName(symbols[i]); - - if (gotAddress != 0 && info.dli_sname != nullptr) - { - int32_t status; - char* demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status); - const char* nameFound = info.dli_sname; - - if (status == 0) - { - nameFound = demangled; - } - - functionName = StringHelper::Sprintf("%s (+0x%X)", nameFound, - (char*)array[i] - (char*)info.dli_saddr); - free(demangled); - } - - fprintf(stderr, "%-3zd %s\n", i, functionName.c_str()); - } - - fprintf(stderr, "\n"); - - free(symbols); - exit(1); -} -#endif +extern const char gBuildHash[]; -int main(int argc, char* argv[]) +int Main(int argc, char* argv[]) { // Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments) @@ -187,10 +123,10 @@ int main(int argc, char* argv[]) } else if (arg == "-eh") // Enable Error Handler { -#if !defined(_MSC_VER) && !defined(__CYGWIN__) +#if defined(__linux__) signal(SIGSEGV, ErrorHandler); signal(SIGABRT, ErrorHandler); -#else +#elif !defined(_MSC_VER) HANDLE_WARNING(WarningType::Always, "tried to set error handler, but this ZAPD build lacks support for one", ""); @@ -329,6 +265,23 @@ int main(int argc, char* argv[]) return 0; } +// Windows doesn't make it easy to get a stack trace from just a signal. So we need to do this messy +// stuf for just windows. +int main(int argc, char* argv[]) +{ +#ifdef _MSC_VER + __try + { + return Main(argc, argv); + } + __except (seh_filter(GetExceptionInformation())) + { + } +#else + return Main(argc, argv); +#endif +} + bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode) { |
