Patch to fix crash on Mac OS X, when calling MemoryDC.GetMultiLineTextExtent with no associated bitm

Hi,
Here is a patch to fix an issue with gr-wxgui running on Mac OS
X, where calls to MemoryDC.GetMultiLineTextExtent fails if there is no
bitmap associated with the MemoryDC, prior to calls to
GetMultiLineTextExtent.

The workaround is to create a 1x1 bitmap, get the text extent, and then
delete the old bitmap and create a new bitmap with the newly computed
text extent.

It doesn’t seem like a good solution from a performance stand-point, but
the wxWidgets guys say that its the only way to do this. It doesn’t
crash on Linux, but on Mac OS X.

Here is the link to the issue tracker:
http://trac.wxwidgets.org/ticket/12486

diff --git a/gr-wxgui/src/python/plotter/gltext.py
b/gr-wxgui/src/python/plotter/gltext.py
index 1b3c047…65d6da0 100644
— a/gr-wxgui/src/python/plotter/gltext.py
+++ b/gr-wxgui/src/python/plotter/gltext.py
@@ -146,8 +146,12 @@ class TextElement(object):
DRAWBACK of the whole conversion thing is a really long time
for creating the
texture. If you see any optimizations that could save time
PLEASE CREATE A PATCH!!!
“”"

  •    # get a memory dc
    
  •    dc = wx.MemoryDC()
    
  •    # get a memory dc
    
  •    # Remark: We need to ensure that a bitmap is associated with 
    

the MemoryDC before

  • making calls to GetMultiLineTextExtent or GetTextExtent.

  •    dc = wx.MemoryDC()
    
  • bmp = wx.EmptyBitmap(1,1)

  • dc.SelectObject(bmp)

      # set our font
      dc.SetFont(self._font)
    

@@ -157,11 +161,18 @@ class TextElement(object):
# sucker gains compared to sizes not of the power of 2.
It’s like
# 500ms --> 0.5ms (on my ATI-GPU powered Notebook). On
Sams nvidia
# machine there don’t seem to occur any losses…bad
drivers?

  •    ow, oh = dc.GetMultiLineTextExtent(self._text)[:2]
    
  •    ow, oh = dc.GetMultiLineTextExtent(self._text)[:2]
    
  • Delete the temporary 1x1 bitmap.

  • del bmp
  • Compute the width and height of the display text

      w, h = self._getUpper2Base(ow), self._getUpper2Base(oh)
    
      self._text_size = wx.Size(ow,oh)
    
  •    self._texture_size = wx.Size(w,h)
    
  •    self._texture_size = wx.Size(w,h)
    
  • Create a new bitmap with the computed width and height of the

display text.
bmp = wx.EmptyBitmap(w,h)

Best regards,

Elvis

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs