From 965224405a6c7db411d9e1bbdef5914cbf80c4ed Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 1 Aug 2014 15:19:04 +0000 Subject: [PATCH] Additional assertions in several wxPGProperty methods. Check if property is attached to the property grid before wxPG methods are invoked. See #16401. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76970 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/propgrid/property.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index c09a3e3ef0..acb4ef1536 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -755,6 +755,8 @@ void wxPGProperty::GetDisplayInfo( unsigned int column, wxString* pString, const wxPGCell** pCell ) { + wxCHECK_RET( GetGrid(), + wxT("Cannot obtain display info for detached property") ); const wxPGCell* cell = NULL; if ( !(flags & wxPGCellRenderer::ChoicePopup) ) @@ -989,8 +991,13 @@ wxString wxPGProperty::GetValueAsString( int argFlags ) const return g_invalidStringContent; } #endif - wxPropertyGrid* pg = GetGrid(); + wxASSERT_MSG( pg, + wxT("Cannot get valid value for detached property") ); + if ( !pg ) + { + return wxEmptyString; + } if ( IsValueUnspecified() ) return pg->GetUnspecifiedValueText(argFlags); @@ -1464,6 +1471,8 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags ) void wxPGProperty::SetValueInEvent( wxVariant value ) const { + wxCHECK_RET( GetGrid(), + wxT("Cannot store pending value for detached property")); GetGrid()->ValueChangeInEvent(value); } @@ -1639,6 +1648,8 @@ const wxPGCell& wxPGProperty::GetCell( unsigned int column ) const return m_cells[column]; wxPropertyGrid* pg = GetGrid(); + wxASSERT_MSG( pg, + wxT("Cannot get cell for detached property") ); if ( IsCategory() ) return pg->GetCategoryDefaultCell(); @@ -2086,6 +2097,10 @@ bool wxPGProperty::RecreateEditor() void wxPGProperty::SetValueImage( wxBitmap& bmp ) { + // We need PG to obtain default image size + wxCHECK_RET( GetGrid(), + wxT("Cannot set image for detached property") ); + delete m_valueBitmap; if ( &bmp && bmp.IsOk() ) @@ -2209,7 +2224,10 @@ int wxPGProperty::GetY2( int lh ) const int wxPGProperty::GetY() const { - return GetY2(GetGrid()->GetRowHeight()); + wxPropertyGrid *pg = GetGrid(); + wxASSERT_MSG( pg, + wxT("Cannot obtain coordinates of detached property") ); + return pg ? GetY2(pg->GetRowHeight()) : 0; } // This is used by Insert etc. @@ -2545,8 +2563,16 @@ void wxPGProperty::Empty() wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y ) const { + wxPropertyGrid *pg = GetGrid(); + wxASSERT_MSG( pg, + wxT("Cannot obtain property item for detached property") ); + if( !pg ) + { + return NULL; + } + unsigned int nextItem = 0; - return GetItemAtY( y, GetGrid()->GetRowHeight(), &nextItem); + return GetItemAtY(y, pg->GetRowHeight(), &nextItem); } void wxPGProperty::DeleteChildren()