diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 9b0357f9d..f643ef0eb 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -95,10 +95,16 @@ GlfwApplication::GlfwApplication(const Arguments& arguments, NoCreateT): .parse(arguments.argc, arguments.argv); #endif - /* Init GLFW */ + /* GLFW before 3.3 doesn't have glfwGetError(), use glfwSetErrorCallback() + even before glfwInit() in that case. It'll be on two lines but better + than getting no reason at all. */ + #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR < 303 glfwSetErrorCallback([](int, const char* const description) { - Error{} << description; + Error{} << "Platform::GlfwApplication:" << description; }); + #endif + + /* Init GLFW */ #ifdef CORRADE_TARGET_APPLE /* Don't change current working directory to Resources/ in the app bundle on Apple platforms. Not sure why this would be done only on a single @@ -108,10 +114,26 @@ GlfwApplication::GlfwApplication(const Arguments& arguments, NoCreateT): glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, false); #endif if(!glfwInit()) { - Error() << "Could not initialize GLFW"; + /* On GLFW before 3.3 the error is printed by the callback that's set + up above */ + #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR < 303 + Error{} << "Platform::GlfwApplication: could not initialize GLFW"; + #else + const char* error = nullptr; + CORRADE_INTERNAL_ASSERT_OUTPUT(glfwGetError(&error) != GLFW_NO_ERROR && error); + Error{} << "Platform::GlfwApplication: could not initialize GLFW:" << error; + #endif std::exit(8); } + /* Set error callback for further errors. On GLFW 3.3+ done after init so + we don't print the error message twice. */ + #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 303 + glfwSetErrorCallback([](int, const char* const description) { + Error{} << "Platform::GlfwApplication:" << description; + }); + #endif + /* Save command-line arguments */ if(args.value("log") == "verbose") _verboseLog = true; const Containers::StringView dpiScaling = args.value("dpi-scaling"); diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index be7d1f11e..8b25a643d 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -239,7 +239,7 @@ Sdl2Application::Sdl2Application(const Arguments& arguments, NoCreateT): #endif if(SDL_Init(SDL_INIT_VIDEO) < 0) { - Error() << "Cannot initialize SDL:" << SDL_GetError(); + Error{} << "Platform::Sdl2Application: could not initialize SDL:" << SDL_GetError(); std::exit(1); }