Opened 6 years ago

Closed 5 years ago

#14916 closed defect (fixed)

Regression: wxTextMeasure breaks wxGCDC DrawText on wxMSW

Reported by: robind Owned by:
Priority: normal Milestone: 2.9.5
Component: wxMSW Version: stable-latest
Keywords: wxTextMeasure wxGCDC GetHDC regression Cc:
Blocked By: Blocking:
Patch: no


The assert in wxTextMeasure::BreginMeasuring is being triggered when trying to draw text on a wxGCDC, either with DrawLabel, or with DrawText when there is a newline in the text. For example:

>>> bmp = wx.EmptyBitmap(100,100)
>>> dc = wx.GCDC(wx.MemoryDC(bmp))
>>> dc
<wx._gdi.GCDC; proxy of <Swig Object of type 'wxGCDC *' at 0x3638110> >
>>> dc.DrawText("Hello\nWorld", 5, 5)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\PROJECTS\wx\2.9\wxPython\wx\", line 3823, in DrawText
    return _gdi_.DC_DrawText(*args, **kwargs)
PyAssertionError: C++ assertion "m_hdc" failed at ..\..\src\msw\textmeasure.cpp(65) in wxTextMeasure::BeginMeasuring(): Must not be used with non-native wxDCs

Can this be worked around in wxTextMeasure, or should wxGCDC be able to return a valid handle from GetHDC?

Change History (1)

comment:1 Changed 5 years ago by VZ

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

(In [73292]) Don't call wxTextMeasure::BeginMeasuring() when using non-native wxDC.

This is useless as we don't use wxTextMeasure in this case but just forward to
the wxDC itself, and also results in an assert in wxMSW wxTextMeasure

Closes #14916.

Note: See TracTickets for help on using tickets.