summaryrefslogtreecommitdiff
path: root/src/client/renderingengine.cpp
diff options
context:
space:
mode:
authorMartin Renold <martin@log2.ch>2018-12-08 16:26:04 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-12-08 16:26:04 +0100
commitb02effdab9b837bd2197ffe7f7f26e0e49fe8acd (patch)
tree63e868b6748b236b105b4d209dab6a048ab19cfe /src/client/renderingengine.cpp
parentf0dca284b3d4fe266e88f6df8c6e3ad9d1411496 (diff)
downloadminetest-b02effdab9b837bd2197ffe7f7f26e0e49fe8acd.tar.gz
minetest-b02effdab9b837bd2197ffe7f7f26e0e49fe8acd.tar.bz2
minetest-b02effdab9b837bd2197ffe7f7f26e0e49fe8acd.zip
Fix crash if display resolution is not set (#7950)
On my wayland / gnome3 setup DisplayHeightMM() returns 0. This resulted in a misleading startup error suggesting to fix my font paths.
Diffstat (limited to 'src/client/renderingengine.cpp')
-rw-r--r--src/client/renderingengine.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp
index 82d1411d6..b18e91f6e 100644
--- a/src/client/renderingengine.cpp
+++ b/src/client/renderingengine.cpp
@@ -624,20 +624,17 @@ static float calcDisplayDensity()
if (x11display != NULL) {
/* try x direct */
- float dpi_height = floor(
- DisplayHeight(x11display, 0) /
- (DisplayHeightMM(x11display, 0) *
- 0.039370) +
- 0.5);
- float dpi_width = floor(
- DisplayWidth(x11display, 0) /
- (DisplayWidthMM(x11display, 0) *
- 0.039370) +
- 0.5);
-
+ int dh = DisplayHeight(x11display, 0);
+ int dw = DisplayWidth(x11display, 0);
+ int dh_mm = DisplayHeightMM(x11display, 0);
+ int dw_mm = DisplayWidthMM(x11display, 0);
XCloseDisplay(x11display);
- return std::max(dpi_height, dpi_width) / 96.0;
+ if (dh_mm != 0 && dw_mm != 0) {
+ float dpi_height = floor(dh / (dh_mm * 0.039370) + 0.5);
+ float dpi_width = floor(dw / (dw_mm * 0.039370) + 0.5);
+ return std::max(dpi_height, dpi_width) / 96.0;
+ }
}
}