From cc67d082f705cd3248705d87701274c8bc0d9a31 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 May 2007 01:19:17 +0000 Subject: [PATCH] deal correctly with having too few items in wxFlexGridSizer (this is not an error, more items could be added later): don't crash and don't assert git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46205 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/sizer.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 1258062d21..c8965d7295 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -1352,6 +1352,8 @@ void wxFlexGridSizer::RecalcSizes() AdjustForGrowables(sz); wxSizerItemList::const_iterator i = m_children.begin(); + const wxSizerItemList::const_iterator end = m_children.end(); + int y = 0; for ( int r = 0; r < nrows; r++ ) { @@ -1359,7 +1361,12 @@ void wxFlexGridSizer::RecalcSizes() { // this row is entirely hidden, skip it for ( int c = 0; c < ncols; c++ ) + { + if ( i == end ) + return; + ++i; + } continue; } @@ -1370,22 +1377,13 @@ void wxFlexGridSizer::RecalcSizes() h = hrow; int x = 0; - for ( int c = 0; c < ncols; c++, ++i ) + for ( int c = 0; c < ncols && i != end; c++, ++i ) { const int wcol = m_colWidths[c]; if ( wcol == -1 ) continue; - // check if there are any remaining children: it may happen that - // the last row is incomplete - if ( i == m_children.end() ) - { - wxASSERT_MSG( r == nrows - 1, _T("too few items") ); - - return; - } - int w = sz.x - x; // max possible value, ensure we don't overflow if ( wcol < w ) w = wcol; @@ -1395,6 +1393,9 @@ void wxFlexGridSizer::RecalcSizes() x += wcol + m_hgap; } + if ( i == end ) + return; + y += hrow + m_vgap; } } -- 2.45.2