I ahev ran into an issue that I can't seem to figure out. The solution is not quite obvious.
So right now, I have 1 frame and 2 panels. The first panel, has 2 buttons in it. When the user clicks on one of the two buttons, the first panel will be deleted and the second one will be created with a few more controls in it (a listbox, static text, and 2 buttons)
Currently, here is a working version of the code for the first panel:
Code: Select all
wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
// This seciton will create a new panel and apply 2 buttons on the panel.
// The 2 buttons are associated with the panel and when the panel is destoryed, so are the buttons.
_initialStartPanel->Create(this, wxID_ANY);
wxButton *buttonNewFile = new wxButton(_initialStartPanel, buttonID::ID_buttonNew, "New", wxDefaultPosition, wxSize(75, 23));
wxButton *buttonOpenFile = new wxButton(_initialStartPanel, buttonID::ID_buttonOpen, "Open", wxDefaultPosition, wxSize(75, 23));
buttonSizer->Add(buttonNewFile, 0, wxALL, 6);
buttonSizer->Add(buttonOpenFile, 0, wxTOP | wxBOTTOM | wxRIGHT, 6);
_initialStartPanel->SetSizer(buttonSizer);
SetSizerAndFit(buttonSizer);
buttonSizer->Fit(_initialStartPanel);
this->SetSize(_initialStartPanel->GetSize());
this->SetMaxSize(this->GetSize());
_UIState = systemState::INITIAL_START_UP;
Code: Select all
wxPanel *problemSelectPanel = new wxPanel();
wxBoxSizer *footerSizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
problemSelectPanel->Create(this, wxID_ANY);
wxStaticText *text = new wxStaticText(problemSelectPanel, wxID_ANY, "Select Physics Problem:");
text->SetFont(*font);
_physicsProblemsListBox->Create(problemSelectPanel, generalFrameButton::ID_LISTBOX, wxDefaultPosition, wxDefaultSize, arrayPhysicsProblem, wxLB_SINGLE);
topSizer->Add(text, 0, wxALL | wxALIGN_LEFT, 6);
topSizer->Add(_physicsProblemsListBox, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_LEFT, 6);
wxButton *backButton = new wxButton(problemSelectPanel, buttonID::ID_buttonBack, "Back", wxDefaultPosition, wxSize(75, 23));
wxButton *finishButton = new wxButton(problemSelectPanel, buttonID::ID_buttonFinish, "Finish", wxDefaultPosition, wxSize(75, 23));
footerSizer->Add(backButton, 0, wxCENTER | wxLEFT | wxRIGHT | wxBOTTOM, 6);
footerSizer->Add(finishButton, 0, wxCENTER | wxBOTTOM | wxRIGHT, 6);
topSizer->Add(footerSizer, 0, wxALIGN_RIGHT);
problemSelectPanel->SetSizer(topSizer);
SetSizerAndFit(topSizer, false);// The error is here!
topSizer->Fit(problemSelectPanel);
this->SetSize(problemSelectPanel->GetSize());
this->SetMaxSize(problemSelectPanel->GetSize());
_UIState = systemState::PHYSICS_CHOOSING;
Interestingly enough, when bypass the first panel and have the second panel draw first, everything is all good. No error codes.
I have a suspicion that something is not being properly destroyed when the frame transitions between panels. But I thought that when you call the destroy function for the panel, it destroys everything including sizers. Is this correct or is there something that I have to do special with the sizers?