pb with wxgrid::Create on wxmac 2.9

Riccardo Cohen rcohen at articque.com
Tue Feb 19 06:29:22 PST 2008


Hi
I have a subclass of wxGrid that is created like this :

art_sheet_displayer::art_sheet_displayer(wxWindow* parent, wxWindowID 
id,const wxPoint& pos, const wxSize& size)
   :wxGrid(parent,id,pos,size,wxNO_BORDER|wxHSCROLL|wxVSCROLL)

Sometimes at creation time, I have a EXC_BAD_ACCESS signal (see 
backtrace at the end of this mail). This is caused by a refresh inside 
wxGrid creation that tries to use m_cornerLabelWin while it is NULL.

Looking at the wxGrid::Create function, I can see this :

bool wxGrid::Create(wxWindow *parent, wxWindowID id,
                           const wxPoint& pos, const wxSize& size,
                           long style, const wxString& name)
{
     if (!wxScrolledWindow::Create(parent, id, pos, size,
                                   style | wxWANTS_CHARS, name))
         return false;

     m_colMinWidths = wxLongToLongHashMap(GRID_HASH_SIZE);
     m_rowMinHeights = wxLongToLongHashMap(GRID_HASH_SIZE);

     Create();

The wxScrolledWindow::Create() function calls a Refresh, which needs 
m_cornerLabelWin, but this member is only initialized in 
wxGrid::Create() called after the scrolled window creation.

I tried to add a test in generic/grid.cpp :

--- grid.cpp    (revision 51909)
+++ grid.cpp    (working copy)
@@ -6893,7 +6893,7 @@
                  m_gridWin->Refresh(eraseb, &anotherrect);
              }
          }
-        else
+        else if (m_cornerLabelWin!=NULL)
          {
              m_cornerLabelWin->Refresh(eraseb, NULL);
              m_colLabelWin->Refresh(eraseb, NULL);


and this seems to be enough to stop the crash, but I'm not sure it is 
the good correction. What is the best ?
Thanks

-----------------------------------
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x0070eef0 in wxGrid::Refresh (this=0x293d4e00, eraseb=true, rect=0x0) 
at ../src/generic/grid.cpp:6898
6898                m_cornerLabelWin->Refresh(eraseb, NULL);
(gdb) p m_cornerLabelWin
$1 = (wxGridCornerLabelWindow *) 0x0
(gdb) bt
#0  0x0070eef0 in wxGrid::Refresh (this=0x293d4e00, eraseb=true, 
rect=0x0) at ../src/generic/grid.cpp:6898
#1  0x00693ad2 in wxWindow::MacUpdateControlFont (this=0x293d4e00) at 
../src/mac/carbon/window.cpp:1112
#2  0x00693b30 in wxWindow::SetFont (this=0x293d4e00, font=@0xbfffe414) 
at ../src/mac/carbon/window.cpp:1119
#3  0x0068c967 in wxWindow::DoSetWindowVariant (this=0x293d4e00, 
variant=wxWINDOW_VARIANT_NORMAL) at ../src/mac/carbon/window.cpp:1104
#4  0x0068c741 in wxWindow::MacPostControlCreate (this=0x293d4e00, 
size=@0x1010e90) at ../src/mac/carbon/window.cpp:1044
#5  0x00692688 in wxWindow::Create (this=0x293d4e00, parent=0x29f18ec0, 
id=106, pos=@0x1010e88, size=@0x1010e90, style=-1071382528, name=void) 
at ../src/mac/carbon/window.cpp:1003
#6  0x006a95eb in wxPanel::Create (this=0x293d4e00, parent=0x29f18ec0, 
id=106, pos=@0x1010e88, size=@0x1010e90, style=-1071382528, 
name=@0xbfffe694) at ../src/generic/panelg.cpp:117
#7  0x0075c63b in wxScrolledWindow::Create (this=0x293d4e00, 
parent=0x29f18ec0, id=106, pos=@0x1010e88, size=@0x1010e90, 
style=-1071382528, name=@0xbfffe694) at ../src/generic/scrlwing.cpp:1428
#8  0x00728708 in wxGrid::Create (this=0x293d4e00, parent=0x29f18ec0, 
id=106, pos=@0x1010e88, size=@0x1010e90, style=-1071644672, name=void) 
at ../src/generic/grid.cpp:4156
#9  0x00728e5c in wxGrid::wxGrid (this=0x293d4e00, parent=0x29f18ec0, 
id=106, pos=@0x1010e88, size=@0x1010e90, style=-1071644672, name=void) 
at ../src/generic/grid.cpp:4149


-- 
Très cordialement,

Riccardo Cohen
-------------------------------------------
Articque
http://www.articque.com
149 av Général de Gaulle
37230 Fondettes - France
tel : 02-47-49-90-49
fax : 02-47-49-91-49




More information about the wx-dev mailing list