Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#16273 closed defect (fixed)

wxFont::GetFaceName() deletes the font handle

Reported by: aebailey82 Owned by: VZ
Priority: low Milestone:
Component: wxMSW Version: 3.0.0
Keywords: wxFont Cc:
Blocked By: Blocking:
Patch: yes

Description

wxFont::GetFaceName() deletes the underlying HFONT. If the font is already used by any windows, those windows are redrawn with the default ugly System font.

wxFontRefData::GetFaceName() caches the retrieved name by calling SetFaceName(), which calls Free(), which calls ::DeleteObject(m_hFont).

The attached program demonstrates the problem. It shows up in my app when I open a configuration dialog that includes font pickers. At that point, any customizable fonts that were used are destroyed.

The only similar issue I found is ancient #960. At first glance I'd guess it's not related, but I'm not sure.

I don't know if the attached patch is kosher, but it fixes my problem by bypassing wxFontRefData::Free().

Attachments (2)

fonttest.cpp download (1.2 KB) - added by aebailey82 3 months ago.
problem demonstration
font_GetFaceName.patch download (634 bytes) - added by aebailey82 3 months ago.
patch candidate

Download all attachments as: .zip

Change History (5)

Changed 3 months ago by aebailey82

problem demonstration

Changed 3 months ago by aebailey82

patch candidate

comment:1 Changed 3 months ago by vadz

Thanks for the test case, explanation and the patch! The latter looks good to me, we probably could make things a bit better by moving GetMSWName() inside wxNativeFontInfo::GetFontName() itself but this change is sufficient to fix the problem for now and I'll apply it soon.

Thanks again!

comment:2 Changed 3 months ago by VZ

  • Owner set to VZ
  • Resolution set to fixed
  • Status changed from new to closed

In 76592:

Don't destroy wxFont from its GetFaceName() in wxMSW.

wxFont::GetFaceName() could destroy the HFONT used by the font accidentally,
avoid it by not invalidating the font when caching its face name.

Closes #16273.

comment:3 Changed 3 months ago by VZ

In 76595:

Don't destroy wxFont from its GetFaceName() in wxMSW.

wxFont::GetFaceName() could destroy the HFONT used by the font accidentally,
avoid it by not invalidating the font when caching its face name.

Closes #16273.

Note: See TracTickets for help on using tickets.