From 6f36917bbffe00404ae6f653e876d57efc25a8ac Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 19 Nov 2001 20:31:44 +0000 Subject: [PATCH] fixed a memory leak and an initialization problem git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12490 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/grid.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 600b5a8ff4..d2f3449f1e 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -2088,6 +2088,9 @@ void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col) } else { + // free the old attribute + m_attrs[(size_t)n].attr->DecRef(); + if ( attr ) { // change the attribute @@ -3607,6 +3610,8 @@ void wxGrid::Create() wxDefaultSize ); SetTargetWindow( m_gridWin ); + + Init(); } @@ -3624,7 +3629,9 @@ bool wxGrid::CreateGrid( int numRows, int numCols, m_table->SetView( this ); m_ownTable = TRUE; m_selection = new wxGridSelection( this, selmode ); - Init(); + + CalcDimensions(); + m_created = TRUE; return m_created; @@ -3632,12 +3639,10 @@ bool wxGrid::CreateGrid( int numRows, int numCols, void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode) { - if ( !m_created ) - { - wxFAIL_MSG( wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") ); - } - else - m_selection->SetSelectionMode( selmode ); + wxCHECK_RET( m_created, + wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") ); + + m_selection->SetSelectionMode( selmode ); } bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, @@ -3664,7 +3669,9 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, if (takeOwnership) m_ownTable = TRUE; m_selection = new wxGridSelection( this, selmode ); - Init(); + + CalcDimensions(); + m_created = TRUE; } @@ -3746,8 +3753,6 @@ void wxGrid::Init() m_extraWidth = m_extraHeight = 50; - - CalcDimensions(); } // ---------------------------------------------------------------------------- -- 2.45.2