From 89f7a5ee753e7c8d8b06f468f15b46c26371e946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 27 Oct 2018 17:43:48 +0200 Subject: [PATCH] Platform: don't assert on X11 DEs that don't have RESOURCE_MANAGER. --- doc/changelog.dox | 3 +++ .../Platform/Implementation/dpiScaling.hpp | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index bc8c7a861..166959320 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -45,6 +45,9 @@ See also: as an alternative to `--magnum-dpi-scaling` command-line parameter. It was also not documented anywhere. Besides that, the default `--magnum-dpi-scaling` value should have been `default` as documented, not `virtual`. +- Don't assert in DPI scaling detection in @ref Platform::Sdl2Application and + @ref Platform::GlfwApplication on X11 DEs that don't create any + `RESOURCE_MANAGER` (see [mosra/magnum#290](https://github.com/mosra/magnum/issues/290)) @section changelog-2018-10 2018.10 diff --git a/src/Magnum/Platform/Implementation/dpiScaling.hpp b/src/Magnum/Platform/Implementation/dpiScaling.hpp index 2c91a59a8..51bf42409 100644 --- a/src/Magnum/Platform/Implementation/dpiScaling.hpp +++ b/src/Magnum/Platform/Implementation/dpiScaling.hpp @@ -102,18 +102,19 @@ inline Float x11DpiScaling() { Containers::ScopedExit closeDisplay{display, xCloseDisplay}; const char* rms = xResourceManagerString(display); - CORRADE_INTERNAL_ASSERT(rms); - XrmDatabase db = xrmGetStringDatabase(rms); - CORRADE_INTERNAL_ASSERT(db); - Containers::ScopedExit closeDb{db, xrmDestroyDatabase}; - - XrmValue value; - char* type{}; - if(xrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value)) { - if(type && strcmp(type, "String") == 0) { - const float scaling = std::stof(value.addr)/96.0f; - CORRADE_INTERNAL_ASSERT(scaling); - return scaling; + if(rms) { + XrmDatabase db = xrmGetStringDatabase(rms); + CORRADE_INTERNAL_ASSERT(db); + Containers::ScopedExit closeDb{db, xrmDestroyDatabase}; + + XrmValue value; + char* type{}; + if(xrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value)) { + if(type && strcmp(type, "String") == 0) { + const float scaling = std::stof(value.addr)/96.0f; + CORRADE_INTERNAL_ASSERT(scaling); + return scaling; + } } }