diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 821fe25221..55e74368fe 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -83,10 +83,12 @@ struct wxGridCellWithAttr wxGridCellWithAttr& operator=(const wxGridCellWithAttr& other) { coords = other.coords; - attr->DecRef(); - attr = other.attr; - attr->IncRef(); - + if (attr != other.attr) + { + attr->DecRef(); + attr = other.attr; + attr->IncRef(); + } return *this; } @@ -2760,13 +2762,20 @@ void wxGridRowOrColAttrData::SetAttr(wxGridCellAttr *attr, int rowOrCol) int i = m_rowsOrCols.Index(rowOrCol); if ( i == wxNOT_FOUND ) { - // add the attribute - m_rowsOrCols.Add(rowOrCol); - m_attrs.Add(attr); + if ( attr ) + { + // add the attribute + m_rowsOrCols.Add(rowOrCol); + m_attrs.Add(attr); + } + // nothing to remove } else { size_t n = (size_t)i; + if ( m_attrs[n] == attr ) + // nothing to do + return; if ( attr ) { // change the attribute