Skip to content

Commit

Permalink
Fix crash if display resolution is not set (#7950)
Browse files Browse the repository at this point in the history
On my wayland / gnome3 setup DisplayHeightMM() returns 0. This resulted in a
misleading startup error suggesting to fix my font paths.
  • Loading branch information
martinxyz authored and nerzhul committed Dec 8, 2018
1 parent f0dca28 commit b02effd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/client/fontengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
}
u32 size = std::floor(RenderingEngine::getDisplayDensity() *
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_alpha = 0;

Expand Down
21 changes: 9 additions & 12 deletions src/client/renderingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit b02effd

Please sign in to comment.