Przeglądaj źródła

fix memory error tree template structure generation

Kolja Strohm 1 rok temu
rodzic
commit
e591551666
1 zmienionych plików z 44 dodań i 8 usunięć
  1. 44 8
      FactoryCraft/Start.cpp

+ 44 - 8
FactoryCraft/Start.cpp

@@ -7,6 +7,9 @@
 #include <Klient.h>
 #ifndef _WINDOWS
 #    include <sys/resource.h>
+#else
+#    define NO_MAIN
+#    include <main.h>
 #endif
 #include <AsynchronCall.h>
 #include <Text.h>
@@ -18,15 +21,45 @@
 
 FactoryCraftServer* mserver = 0;
 
-void exit()
+#ifdef _WINDOWS
+LONG WINAPI exceptionHandler(struct _EXCEPTION_POINTERS* apExceptionInfo)
 {
+    Sleep(10000);
+    std::cout << "ERROR: Creating dump";
+    std::cout.flush();
+    createMinidump(apExceptionInfo);
     if (mserver)
     {
         std::cout << "The server terminated unexpectedly. Trying to save game "
                      "progress.\n";
         mserver->close();
     }
+    return EXCEPTION_CONTINUE_SEARCH;
 }
+#endif
+
+void onError(int i)
+{
+    Sleep(10000);
+    std::cout << "ERROR: Creating dump";
+    std::cout.flush();
+    createMinidump(0);
+    if (mserver)
+    {
+        std::cout << "The server terminated unexpectedly. Trying to save game "
+                     "progress.\n";
+        mserver->close();
+    }
+}
+
+void onExit()
+{
+    Sleep(10000);
+    std::cout << "Programm exited";
+    std::cout.flush();
+    onError(0);
+}
+
 
 bool exited = false;
 
@@ -141,6 +174,9 @@ public:
 
 int main()
 {
+#ifdef _WINDOWS
+    SetUnhandledExceptionFilter(exceptionHandler);
+#endif
     Framework::initFramework();
 
 #ifndef _WINDOWS
@@ -199,13 +235,13 @@ int main()
     }
 
     mserver = new FactoryCraftServer(dat);
-    std::atexit(exit);
-    signal(SIGTERM, exit);
-    signal(SIGSEGV, exit);
-    signal(SIGILL, exit);
-    signal(SIGABRT, exit);
-    signal(SIGFPE, exit);
-    signal(SIGINT, exit);
+    std::atexit(onExit);
+    signal(SIGTERM, onError);
+    signal(SIGSEGV, onError);
+    signal(SIGILL, onError);
+    signal(SIGABRT, onError);
+    signal(SIGFPE, onError);
+    signal(SIGINT, onError);
 
     new Framework::AsynchronCall("Commander", []() {
         while (mserver)