Changeset 6abfd07 in opengl-game for new-game.cpp


Ignore:
Timestamp:
May 31, 2019, 6:26:19 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
b373466
Parents:
a23fc08
Message:

Create a log with a stack-trace when the game crashes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    ra23fc08 r6abfd07  
    3535#include "Compiler.h"
    3636
    37 #ifdef WINDOWS
    38    #include <windows.h>
    39    #include <excpt.h>
    40    #include <io.h>
    41 
    42    #include "FileStackWalker.h"
    43 #else
    44    // TODO: Move as much Windows crash-logging stuff into CrashLogger as well
    45    #include "CrashLogger.h"
    46 #endif
     37#include "CrashLogger.h"
    4738
    4839using namespace std;
     
    300291*/
    301292
    302 CrashLogger logger;
    303 
    304293// Helps to test logging during crashes
    305 /*
    306 void badFunc() {
     294int badFunc() {
    307295   int* test = NULL;
     296
     297   string test2 = "lol";
     298   cout << test2 << endl;
     299
    308300   *test = 1;
    309 }
    310 */
    311 
    312 #ifdef WINDOWS
    313 
    314 // Give it a file handle to crash.log instead (using the code in CrashLogger.cpp)
    315 FileStackWalker sw(2);
    316 
    317 bool handleException(unsigned int expCode, EXCEPTION_POINTERS* pExp, HANDLE thread);
    318 #endif
     301   return *test;
     302}
     303
     304int __main(int argc, char* argv[]);
    319305
    320306int main(int argc, char* argv[]) {
    321 #ifdef WINDOWS
    322    __try {
    323       __main(argc, argv);
    324       // maybe do this and call a function inside CrashLogger
    325       // In that case, also pass GetCurrentThread() as a parameter to then pass to handleException
    326       // I could also move almost all of this into CrashLogger by creating a function in CrashLogger that takes a reference
    327       // to the effective main function and, for Windows, wraps it in all this error-handling stuff
    328    } __except( handleException(GetExceptionCode(), GetExceptionInformation(), GetCurrentThread()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER) {
    329       _write(2, "CAUGHT\n", 7);
    330    }
     307   CrashLogger logger(__main, argc, argv);
    331308
    332309   exit(0);
     
    334311
    335312int __main(int argc, char* argv[]) {
    336 #endif
    337313   cout << "New OpenGL Game" << endl;
    338314
     
    1023999      delete *it;
    10241000   }
    1025 }
    1026 
    1027 #ifdef WINDOWS
    1028 bool handleException(unsigned int expCode, EXCEPTION_POINTERS* pExp, HANDLE thread) {
    1029    if (pExp != NULL) {
    1030       sw.ShowCallstack(thread, pExp->ContextRecord);
    1031    }
    1032 
    1033    if (expCode == EXCEPTION_ACCESS_VIOLATION) {
    1034       _write(2, "ACCESS VIOLATION\n", 17);
    1035    }
    1036 
    1037    return true;
    1038 }
    1039 #endif
     1001
     1002   return 0;
     1003}
    10401004
    10411005void glfw_error_callback(int error, const char* description) {
Note: See TracChangeset for help on using the changeset viewer.