(2.9.1) wxGridBagSizer assertation

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

(2.9.1) wxGridBagSizer assertation

Post by ArKay »

Hello,

I've been building an application with the help of DialogBlocks. I have a GridBagSizer inside a wxDialog. The generated code for it looks like this:

Code: Select all

	wxGridBagSizer* itemGridBagSizer46 = new wxGridBagSizer(0, 0);
	itemGridBagSizer46->AddGrowableCol(1);
	itemGridBagSizer46->AddGrowableCol(3);
	itemGridBagSizer46->AddGrowableCol(5);
	itemGridBagSizer46->SetEmptyCellSize(wxSize(10, 20));
	itemStaticBoxSizer45->Add(itemGridBagSizer46, 1, wxGROW|wxALL, 2);
When I run the code in Debug I am getting the following assertation:

ASSERT INFO:
/var/tmp/portage/x11-libs/wxGTK-2.9.1/work/wxWidgets-2.9.1/src/common/sizer.cpp(1948): assert "!m_cols || idx < (size_t)m_cols" failed in AddGrowableCol(): invalid column index

BACKTRACE:
[1] wxOnAssert(char const*, int, char const*, char const*, char const*)
[2] ServiceDetailsDlg::CreateControls() /home/arkay/32Pro/NDE/NDE/servicedetailsdlg.cpp:330
[3] ServiceDetailsDlg::Create(wxWindow*, Service*, ServiceData*, int, wxString const&, wxPoint const&, wxSize const&, long) /home/arkay/32Pro/NDE/NDE/servicedetailsdlg.cpp:133
[4] ServiceDetailsDlg() /home/arkay/32Pro/NDE/NDE/servicedetailsdlg.cpp:117
[5] ServiceListCtrl::OnItemActivated(wxListEvent&) /home/arkay/32Pro/NDE/NDE/servicelistctrl.cpp:717
[6] wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) cons)
[7] wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&)
[8] wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*)
[9] wxEvtHandler::ProcessEventLocally(wxEvent&)
[10] wxEvtHandler::ProcessEvent(wxEvent&)
[11] wxScrollHelperEvtHandler::ProcessEvent(wxEvent&)
[12] wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) cons)
[13] wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&)
[14] wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*)
[15] wxEvtHandler::ProcessEventLocally(wxEvent&)
[16] wxEvtHandler::ProcessEvent(wxEvent&)
[17] wxEvtHandler::SafelyProcessEvent(wxEvent&)
[18] g_closure_invoke()
[19] g_signal_emit_valist()
[20] g_signal_emit()
[21] gtk_propagate_event()
[22] gtk_main_do_event()
[23] g_main_context_dispatch()
[24] g_main_loop_run()
[25] gtk_main()

So the AddGrowableCol() calls generate this assertation, if I ignore them everything works. What am I missing here?

Thanks,
Rainer
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

The name AddGrowableCol() is a little misleading, because it doesn't add a column, it just sets a (already existing) column to be growable. And as no column exists when you call that method, you get the assert message.

Call AddGrowableCol() after you added all items to the sizer.
Use the source, Luke!
ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay »

The problem is that this code is generated by DialogBlocks. So if I change the order it'll be overwritten the next time I save.

The FlexGridSizer I use a couple of lines before doesn't seem to have that limitation since the following code doesn't cause an assert.

wxFlexGridSizer* itemFlexGridSizer32 = new wxFlexGridSizer(3, 4, 0, 0);
itemFlexGridSizer32->AddGrowableCol(1);
itemFlexGridSizer32->AddGrowableCol(3);
itemBoxSizer31->Add(itemFlexGridSizer32, 0, wxGROW|wxALL, 2);

Maybe I should also use that here instead? I can't remember what the difference is, I had started this project 2 years ago and just gotten back to it :lol:
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

When you create the wxFlexGridSizer you already set the number of rows/columns, so you don't get the assert.

Main difference is that wxGridBagSizer can have empty cells and that cells can span several rows or columns.
Use the source, Luke!
ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay »

Empty cells, that's why I've used it. OK, so now I know my options. Thanks for the help :)
Post Reply