Fix using invalid HFONT in wxGetTextMetrics()

If the window has no valid font, GetFont() returns a temporary font.
Extend this font lifetime, so the HFONT remains valid till the end of
the function.
This commit is contained in:
Maarten Bent
2019-02-17 19:49:34 +01:00
committed by Vadim Zeitlin
parent 63c118f186
commit c7efab6d8a

View File

@@ -7421,7 +7421,12 @@ static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win)
#if !wxDIALOG_UNIT_COMPATIBILITY
// and select the current font into it
HFONT hfont = GetHfontOf(win->GetFont());
// Note that it's important to extend the lifetime of the possibly
// temporary wxFont returned by GetFont() to ensure that its HFONT remains
// valid.
const wxFont& f(win->GetFont());
HFONT hfont = GetHfontOf(f);
if ( hfont )
{
hfont = (HFONT)::SelectObject(hdc, hfont);