Opened 4 months ago

Closed 3 months ago

#16361 closed defect (fixed)

assertion in wxFlagsProperty

Reported by: anhsoft Owned by: AW
Priority: normal Milestone:
Component: wxPropertyGrid Version: dev-latest
Keywords: wxFlagsProperty wxPGCheckBoxEditor Cc:
Blocked By: Blocking:
Patch: no

Description

Assertion text:

./src/propgrid/editors.cpp(1666): assert "cb" failed in UpdateControl()

Crucial code, where it appears:

[header.h]

class myFlagsProperty: public wxFlagsProperty {
public:
   myFlagsProperty(wxPGChoices& choices): wxFlagsProperty(wxT("my_flags"), wxPG_LABEL, choices, 0) {}

   virtual bool ValidateValue(wxVariant& value, wxPGValidationInfo& validationInfo) const {
      return false; // i.e. when return false in ValidateValue()
   }
};

[source.cpp]

wxPGProperty* property;
wxPGChoices choices;

SetValidationFailureBehavior(wxPG_VFB_MARK_CELL);

choices.Add(wxSTR("1"), 1); // add my choices
choices.Add(wxSTR("2"), 2);
choices.Add(wxSTR("4"), 4);
property = Append(new myFlagsProperty(choices));

property->SetAttribute(wxPG_BOOL_USE_CHECKBOX, true); // use CheckBoxes instead ComboBoxes
  • If don't set wxPG_BOOL_USE_CHECKBOX attribute, then the assertion not generates;
  • If comment the 'SetValidationFailureBehavior' func, then shows popup warning "You have entered invalid value. Press ESC to cancel editing" before appears this assert.

Attachments (1)

wxFlagsProperty_bug_src.zip download (2.4 KB) - added by anhsoft 4 months ago.
src

Download all attachments as: .zip

Change History (3)

Changed 4 months ago by anhsoft

src

comment:1 Changed 3 months ago by awi

  • Keywords wxPGCheckBoxEditor added
  • Status changed from new to confirmed
  • Version changed from 3.0.0 to dev-latest

The reason for this issue is the fact that when check box is clicked then validation function is executed before editable check box associated with wxFlagsProperty-derived object becomes fully operational (wxPGCheckBoxEditor object is created bot not yet registered and thus not exposed).

Patch to propgrid sample reproducing the issue:

  • samples/propgrid/propgrid.cpp

    a b void FormMain::OnResize( wxSizeEvent& event ) 
    639639void FormMain::OnPropertyGridChanging( wxPropertyGridEvent& event ) 
    640640{ 
    641641    wxPGProperty* p = event.GetProperty(); 
     642    wxLogDebug("wxEVT_PG_CHANGING(%s)", p->GetLabel().c_str()); 
    642643 
    643644    if ( p->GetName() == wxT("Font") ) 
    644645    { 
    void FormMain::OnPropertyGridChanging( wxPropertyGridEvent& event ) 
    669670void FormMain::OnPropertyGridChange( wxPropertyGridEvent& event ) 
    670671{ 
    671672    wxPGProperty* property = event.GetProperty(); 
     673    wxLogDebug("wxEVT_PG_CHANGED(%s)", property->GetLabel().c_str()); 
    672674 
    673675    const wxString& name = property->GetName(); 
    674676 
    void FormMain::OnEnableCommonValues(wxCommandEvent& WXUNUSED(event)) 
    10221024        wxMessageBox(wxT("First select a property")); 
    10231025} 
    10241026 
     1027class TestFlagsProperty: public wxFlagsProperty 
     1028{ 
     1029public: 
     1030   TestFlagsProperty(const wxString &label, wxPGChoices& choices): wxFlagsProperty(label, wxPG_LABEL, choices, 0) {} 
     1031 
     1032   virtual bool ValidateValue(wxVariant& WXUNUSED(value), wxPGValidationInfo& WXUNUSED(validationInfo)) const 
     1033   { 
     1034      return false; 
     1035   } 
     1036}; 
     1037 
    10251038void FormMain::PopulateWithStandardItems () 
    10261039{ 
    10271040    wxPropertyGridManager* pgman = m_pPropGridManager; 
    void FormMain::PopulateWithStandardItems () 
    11681181        pg->SetPropertyCell( p, 3, wxT("Cell 3"), bmp ); 
    11691182        pg->SetPropertyCell( p, 4, wxT("Cell 4"), wxNullBitmap, *wxWHITE, *wxBLACK ); 
    11701183    } 
     1184 
     1185   wxPGChoices choices; 
     1186   choices.Add(wxT("flag 1"), 1); 
     1187   choices.Add(wxT("flag 2"), 2); 
     1188   choices.Add(wxT("flag 3"), 4); 
     1189 
     1190   pg->SetValidationFailureBehavior(wxPG_VFB_MARK_CELL); 
     1191   wxPGProperty* prop = pg->Append(new TestFlagsProperty(wxT("Test Flags"), choices)); 
     1192   prop->SetAttribute(wxPG_BOOL_USE_CHECKBOX, true); 
    11711193} 
    11721194 
    11731195// ----------------------------------------------------------------------- 

comment:2 Changed 3 months ago by AW

  • Owner set to AW
  • Resolution set to fixed
  • Status changed from confirmed to closed

In 76885:

Defer using of editable check box in wxPG until it is fully initialized.

Currently, when wxPGCheckBoxEditor is clicked then associated check box (wxSimpleCheckBox) is created and immediately after that its state is changed. This causes problems when underlaying validation is performed because the check box object is not yet registered as an active editor and thus it is not visible from within e.g. validation function.
We need to defer changing the initial state of the check box until this box is registered by queuing the special event which will be processed after initialization.

Closes #16361.

Note: See TracTickets for help on using tickets.