I used dynamic event binding and run under Debug mode.
Here is my example codes:
Code: Select all
#define wxID_App_TEST 100000
///////////////////////////////////
class myFrame : public wxFrame {
private:
int user_id;
private:
wxRibbonBar *create_ribbon();
wxRibbonBar * ribbbon;
private:
void OnClick(wxRibbonButtonBarEvent & event);
public:
myFrame():wxFrame(NULL, wxID_ANY, "test", wxDefaultPosition, wxSize(800, 450), wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER) {
this->ribbon = NULL;
this->user_id= 0;
this->ribbbon = this->create_ribbon();
}
~myFrame();
};
wxRibbonBar *myFrame::create_ribbon()
{
wxRibbonBar * rbar = new wxRibbonBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxRIBBON_BAR_FLOW_HORIZONTAL | wxRIBBON_BAR_SHOW_PAGE_LABELS);
wxRibbonPage *pApplication = new wxRibbonPage(this->ribbbon, wxID_ANY, "Application", wxNullBitmap);
wxRibbonPanel *pApplicationPanel = new wxRibbonPanel(pApplication , wxID_ANY, "Test", wxNullBitmap,
wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_NO_AUTO_MINIMISE);
wxRibbonButtonBar *pAppTestBar = new wxRibbonButtonBar(pApplicationPanel);
pAppTestBar->AddButton(wxID_App_TEST, "Test", wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(48,48)));
this->ribbbon->Realize();
Bind(wxEVT_RIBBONBUTTONBAR_CLICKED, &myFrame ::OnClick, this, wxID_App_TEST, wxID_ANY, this);
return rbar;
}
void myFrame::OnClick(wxRibbonButtonBarEvent& event)
{
//@@preconditions
//@@end preconditions
myFrame* userdata = static_cast<myFrame*>(event.GetEventUserData()); assert(userdata);
userdata->user_id = 1000;
}
My problem is the program will crash, the crash point in the ~myFrame()!
If I don't pass userdata in Bind function(Bind(wxEVT_RIBBONBUTTONBAR_CLICKED, &myFrame ::OnClick, this, wxID_App_TEST)), then no crash. But pass userdata is really important to me.
Is there somebody could help me? Thanks!