diff --git a/src/Error.cpp b/src/Error.cpp index 19f3fb7..ddfc31c 100644 --- a/src/Error.cpp +++ b/src/Error.cpp @@ -1,4 +1,9 @@ #include "Error.h" -#include Error::Error(std::string location) { object = location; } +void Error::crash(std::string msg) { throw object + ": " + msg; } +void Error::crash(std::string reason, std::string msg) { + throw object + ": " + reason + ": " + msg; +} +void Error::warn(std::string msg) { throw object + ": " + msg; } +void Error::log(std::string msg) { throw object + ": " + msg; } diff --git a/src/Error.h b/src/Error.h index d798030..0d827c8 100644 --- a/src/Error.h +++ b/src/Error.h @@ -8,4 +8,11 @@ private: public: Error(std::string location); + + // TODO: make the crash break game loop + void crash(std::string msg); + void crash(std::string reason, std::string msg); + void warn(std::string msg); + // TODO: write log issues to a file rather than throw + void log(std::string msg); }; diff --git a/src/main.cpp b/src/main.cpp index f9c8319..f8e20f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,8 +24,6 @@ const char *fragmentShaderSource = // Include error class #include "Error.h" -#include -// TODO: Remove check that error class was included properly Error error("main"); // TODO: Create Error handling class @@ -33,7 +31,10 @@ Error error("main"); int main(int argc, char **argv) { // Initialise SDL2 // TODO: Check if sdl initialised - SDL_Init(SDL_INIT_EVERYTHING); + if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { + error.crash("Unable to initialise SDL: ", SDL_GetError()); + return 1; + } // Make OpenGL use double buffering (Render game first then shove to output) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);