diff --git a/examples/debug/main.cpp b/examples/debug/main.cpp index 017c954..d5f6e6d 100644 --- a/examples/debug/main.cpp +++ b/examples/debug/main.cpp @@ -69,7 +69,7 @@ int main(int argc, char** argv) { shader = oglu::MakeShader("shaders/vertexShader.vert", "shaders/fragmentShader.frag"); } - catch (const std::exception& e) + catch (const std::runtime_error& e) { std::cerr << e.what() << std::endl; return -1; diff --git a/include/core.hpp b/include/core.hpp index b4b26b6..2d47e28 100644 --- a/include/core.hpp +++ b/include/core.hpp @@ -10,6 +10,8 @@ #define CORE_HPP #include +#include +#include #include #ifdef OGLU_WIN32 diff --git a/src/openglu.cpp b/src/openglu.cpp index b174452..a237932 100644 --- a/src/openglu.cpp +++ b/src/openglu.cpp @@ -9,7 +9,7 @@ namespace oglu { if (!gladLoadGLLoader(proc)) { - throw std::exception("Failed to initialize GLAD"); + throw std::runtime_error("Failed to initialize GLAD"); } } diff --git a/src/shader.cpp b/src/shader.cpp index ca65e2c..3cc1873 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -38,8 +38,10 @@ namespace oglu if (!success) { glGetShaderInfoLog(vertexShader, 512, NULL, infoLog); + std::string err = ("Failed to compile shader " + std::string(vertexShaderFile) + "\n" + infoLog); delete source; - throw std::exception(std::string("Failed to compile shader " + std::string(vertexShaderFile) + "\n" + infoLog).c_str()); + delete infoLog; + throw std::runtime_error(err); } delete source; @@ -54,8 +56,10 @@ namespace oglu if (!success) { glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog); + std::string err = ("Failed to compile shader " + std::string(fragmentShaderFile) + "\n" + infoLog); delete source; - throw std::exception(std::string("Failed to compile shader " + std::string(fragmentShaderFile) + "\n" + infoLog).c_str()); + delete infoLog; + throw std::runtime_error(err); } delete source; @@ -69,7 +73,9 @@ namespace oglu if (!success) { glGetProgramInfoLog(program, 512, NULL, infoLog); - throw std::exception(std::string("Failed to link program.\n" + std::string(infoLog)).c_str()); + std::string err = ("Failed to link program.\n" + std::string(infoLog)); + delete infoLog; + throw std::runtime_error(err); } // Dispose of shader objects @@ -443,9 +449,10 @@ namespace oglu if (!file.good()) { file.close(); - throw std::exception(std::string("Failed to open shader file: " + std::string(filename)).c_str()); + throw std::runtime_error(std::string("Failed to open shader file: " + std::string(filename))); } + // TODO: This is just horrendous std::string str((std::istreambuf_iterator(file)), std::istreambuf_iterator()); (*buffer) = (char*)malloc(str.size() + 1); memcpy(*buffer, str.c_str(), str.size()); diff --git a/src/texture.cpp b/src/texture.cpp index 73d7cd9..4f7387b 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -2,6 +2,7 @@ #define STB_IMAGE_IMPLEMENTATION #include +#include namespace oglu { @@ -27,7 +28,8 @@ namespace oglu stbi_uc* data = stbi_load(filename, &width, &height, &nrChannels, 0); if (data == nullptr) { - throw stbi_failure_reason(); + std::string err = std::string(stbi_failure_reason()); + throw std::runtime_error(err); } glGenTextures(1, &texture);