Browse Source

Platform: prefix error messages coming from SDL2 and GLFW.

So it's clear the error comes from Magnum and not something else. Also
unify these and make GLFW not report the error on two lines if the init
fails.

Ugh, except that glfwGetError() is only there since 3.3, so I have to
keep the old code as well.
pull/680/head
Vladimír Vondruš 11 months ago
parent
commit
be38d5e2bb
  1. 28
      src/Magnum/Platform/GlfwApplication.cpp
  2. 2
      src/Magnum/Platform/Sdl2Application.cpp

28
src/Magnum/Platform/GlfwApplication.cpp

@ -95,10 +95,16 @@ GlfwApplication::GlfwApplication(const Arguments& arguments, NoCreateT):
.parse(arguments.argc, arguments.argv); .parse(arguments.argc, arguments.argv);
#endif #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) { glfwSetErrorCallback([](int, const char* const description) {
Error{} << description; Error{} << "Platform::GlfwApplication:" << description;
}); });
#endif
/* Init GLFW */
#ifdef CORRADE_TARGET_APPLE #ifdef CORRADE_TARGET_APPLE
/* Don't change current working directory to Resources/ in the app bundle /* 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 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); glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, false);
#endif #endif
if(!glfwInit()) { 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); 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 */ /* Save command-line arguments */
if(args.value("log") == "verbose") _verboseLog = true; if(args.value("log") == "verbose") _verboseLog = true;
const Containers::StringView dpiScaling = args.value<Containers::StringView>("dpi-scaling"); const Containers::StringView dpiScaling = args.value<Containers::StringView>("dpi-scaling");

2
src/Magnum/Platform/Sdl2Application.cpp

@ -239,7 +239,7 @@ Sdl2Application::Sdl2Application(const Arguments& arguments, NoCreateT):
#endif #endif
if(SDL_Init(SDL_INIT_VIDEO) < 0) { 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); std::exit(1);
} }

Loading…
Cancel
Save