mirror of
https://github.com/minetest/minetest.git
synced 2024-12-25 15:42:24 +01:00
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.
This commit is contained in:
parent
f0dca284b3
commit
b02effdab9
@ -315,6 +315,11 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
|
|||||||
}
|
}
|
||||||
u32 size = std::floor(RenderingEngine::getDisplayDensity() *
|
u32 size = std::floor(RenderingEngine::getDisplayDensity() *
|
||||||
m_settings->getFloat("gui_scaling") * basesize);
|
m_settings->getFloat("gui_scaling") * basesize);
|
||||||
|
if (size == 0) {
|
||||||
|
errorstream << "FontEngine: attempt to use font size 0" << std::endl;
|
||||||
|
errorstream << " display density: " << RenderingEngine::getDisplayDensity() << std::endl;
|
||||||
|
abort();
|
||||||
|
}
|
||||||
u32 font_shadow = 0;
|
u32 font_shadow = 0;
|
||||||
u32 font_shadow_alpha = 0;
|
u32 font_shadow_alpha = 0;
|
||||||
|
|
||||||
|
@ -624,22 +624,19 @@ static float calcDisplayDensity()
|
|||||||
|
|
||||||
if (x11display != NULL) {
|
if (x11display != NULL) {
|
||||||
/* try x direct */
|
/* try x direct */
|
||||||
float dpi_height = floor(
|
int dh = DisplayHeight(x11display, 0);
|
||||||
DisplayHeight(x11display, 0) /
|
int dw = DisplayWidth(x11display, 0);
|
||||||
(DisplayHeightMM(x11display, 0) *
|
int dh_mm = DisplayHeightMM(x11display, 0);
|
||||||
0.039370) +
|
int dw_mm = DisplayWidthMM(x11display, 0);
|
||||||
0.5);
|
|
||||||
float dpi_width = floor(
|
|
||||||
DisplayWidth(x11display, 0) /
|
|
||||||
(DisplayWidthMM(x11display, 0) *
|
|
||||||
0.039370) +
|
|
||||||
0.5);
|
|
||||||
|
|
||||||
XCloseDisplay(x11display);
|
XCloseDisplay(x11display);
|
||||||
|
|
||||||
|
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;
|
return std::max(dpi_height, dpi_width) / 96.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* return manually specified dpi */
|
/* return manually specified dpi */
|
||||||
return g_settings->getFloat("screen_dpi") / 96.0;
|
return g_settings->getFloat("screen_dpi") / 96.0;
|
||||||
|
Loading…
Reference in New Issue
Block a user