Changeset d9b6a1c in opengl-game


Ignore:
Timestamp:
May 24, 2019, 5:37:05 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
98f06d9
Parents:
caa2359
Message:

Print a stack trace in the event of a crash. Currently, the code for this on Windows outputs the stack trace to stderr, not to a log file.

Files:
7 added
4 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rcaa2359 rd9b6a1c  
    55
    66gl.log
     7crash.log
    78
    89imgui.ini
  • NewOpenGLGame.vcxproj

    rcaa2359 rd9b6a1c  
    135135  </ItemDefinitionGroup>
    136136  <ItemGroup>
     137    <ClCompile Include="CrashLogger.cpp" />
    137138    <ClCompile Include="IMGUI\imgui.cpp" />
    138139    <ClCompile Include="IMGUI\imgui_demo.cpp" />
     
    141142    <ClCompile Include="logger.cpp" />
    142143    <ClCompile Include="new-game.cpp" />
     144    <ClCompile Include="StackWalker.cpp" />
    143145    <ClCompile Include="stb_image_write.h" />
    144146    <ClCompile Include="stb_image.cpp" />
    145147  </ItemGroup>
    146148  <ItemGroup>
     149    <ClInclude Include="CrashLogger.h" />
    147150    <ClInclude Include="IMGUI\imgui.h" />
    148151    <ClInclude Include="IMGUI\imgui_internal.h" />
     
    152155    <ClInclude Include="imgui_impl_glfw_gl3.h" />
    153156    <ClInclude Include="logger.h" />
     157    <ClInclude Include="StackWalker.h" />
    154158    <ClInclude Include="stb_image.h" />
    155159    <ClInclude Include="utils.h" />
  • makefile

    rcaa2359 rd9b6a1c  
    11OS = $(shell uname)
    22CC = g++
    3 CFLAGS = -std=c++0x -Wall -pedantic#-Wextra
     3CFLAGS = -std=c++0x -Wall -pedantic#-Wextra -fno-inline
    44
    55ifeq ($(OS),Darwin)
     
    1515# as this well prevent regenerating .o files for unchanged .cpp files
    1616
    17 newgame: new-game.cpp logger.cpp stb_image.cpp imgui_impl_glfw_gl3.cpp $(IMGUI_FILES)
     17newgame: new-game.cpp logger.cpp stb_image.cpp imgui_impl_glfw_gl3.cpp CrashLogger.cpp $(IMGUI_FILES)
    1818        $(CC) $^ $(DEP) $(CFLAGS) -o $@
    1919
  • new-game.cpp

    rcaa2359 rd9b6a1c  
    3232#include "logger.h"
    3333#include "utils.h"
     34
     35#include "Compiler.h"
     36
     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
    3447
    3548using namespace std;
     
    212225void calculateObjectBoundingBox(SceneObject* obj);
    213226
    214 void initializeParticleEffectBuffers(map<GLuint, BufferInfo>& shaderBufferInfo,
    215                   map<ObjectType, ShaderModelGroup>& modelGroups,
    216                   GLuint ubo);
    217 
    218227void populateBuffers(vector<SceneObject*>& objects,
    219228                  map<GLuint, BufferInfo>& shaderBufferInfo,
     
    297306*/
    298307
     308CrashLogger logger;
     309
     310// Helps to test logging during crashes
     311/*
     312void badFunc() {
     313   int* test = NULL;
     314   *test = 1;
     315}
     316*/
     317
     318#ifdef WINDOWS
     319
     320// Give it a file handle to crash.log instead (using the code in CrashLogger.cpp)
     321FileStackWalker sw(2);
     322
     323bool handleException(unsigned int expCode, EXCEPTION_POINTERS* pExp, HANDLE thread);
     324#endif
     325
    299326int main(int argc, char* argv[]) {
     327#ifdef WINDOWS
     328   __try {
     329      __main(argc, argv);
     330      // maybe do this and call a function inside CrashLogger
     331      // In that case, also pass GetCurrentThread() as a parameter to then pass to handleException
     332      // I could also move almost all of this into CrashLogger by creating a function in CrashLogger that takes a reference
     333      // to the effective main function and, for Windows, wraps it in all this error-handling stuff
     334   } __except( handleException(GetExceptionCode(), GetExceptionInformation(), GetCurrentThread()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER) {
     335      _write(2, "CAUGHT\n", 7);
     336   }
     337
     338   exit(0);
     339}
     340
     341int __main(int argc, char* argv[]) {
     342#endif
    300343   cout << "New OpenGL Game" << endl;
    301344
     
    309352   }
    310353
    311 #ifdef __APPLE__
     354#ifdef MAC
    312355   glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    313356   glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
     
    9731016      delete *it;
    9741017   }
    975 
    976    return 0;
    977 }
     1018}
     1019
     1020#ifdef WINDOWS
     1021bool handleException(unsigned int expCode, EXCEPTION_POINTERS* pExp, HANDLE thread) {
     1022   if (pExp != NULL) {
     1023      sw.ShowCallstack(thread, pExp->ContextRecord);
     1024   }
     1025
     1026   if (expCode == EXCEPTION_ACCESS_VIOLATION) {
     1027      _write(2, "ACCESS VIOLATION\n", 17);
     1028   }
     1029
     1030   return true;
     1031}
     1032#endif
    9781033
    9791034void glfw_error_callback(int error, const char* description) {
Note: See TracChangeset for help on using the changeset viewer.