diff --git a/common/pg_properties.cpp b/common/pg_properties.cpp index b40e650f54..c851a1d25d 100644 --- a/common/pg_properties.cpp +++ b/common/pg_properties.cpp @@ -303,6 +303,10 @@ void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect, if( index < 0 ) index = GetIndex(); + // GetIndex can return -1 when the control hasn't been set up yet + if( index < 0 || index >= static_cast( GetChoices().GetCount() ) ) + return; + wxString layer = GetChoices().GetLabel( index ); wxColour color = GetColor( layer ); @@ -312,4 +316,6 @@ void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect, aDC.SetPen( *wxTRANSPARENT_PEN ); aDC.SetBrush( wxBrush( color ) ); aDC.DrawRectangle( aRect ); + + aPaintData.m_drawnWidth = aRect.width; }