TOOLS: Fix crash when compiling with wxWidgets 2.9

The issue occurred on the Intro page when clicking on the Compress,
Extract or Advanced button. The page and therefore the buttons were
destroyed from the event handler of the button that was clicked. While
this work with wxWidgets 2.8 this seems dangerous. And this caused
a crash with wxWidgets 2.9 (at least on mac-cocoa). The page deletion
is now delayed.
This commit is contained in:
Thierry Crozat
2012-11-27 03:18:04 +00:00
parent c5cdaa0c28
commit d02758eef0
3 changed files with 26 additions and 5 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
For a more comprehensive changelog of the latest experimental code, see:
https://github.com/scummvm/scummvm-tools/commits/
1.5.0 (????-??-??)
1.6.0 (????-??-??)
- Fix crash when compiling with wxWidgets 2.9.
- Add two tools to extract and repackage the Soltys game data.
- Fix bug #3093138: "compress_tucker with ScummVM CLI Tools not working".
- Fix bug #3280674: "ScummTools do not compress monster.sou of german fdd-version"
+21 -2
View File
@@ -226,6 +226,9 @@ ScummToolsFrame::ScummToolsFrame(const wxString &title, const wxPoint &pos, cons
_buttons = new WizardButtons(main, linetext, _configuration);
sizer->Add(_buttons, wxSizerFlags().Border().Center().Expand());
// Delete old panels on idle event
Connect(wxEVT_IDLE, wxIdleEventHandler(ScummToolsFrame::destroyOldPanels), NULL, this);
main->SetSizer(sizer);
}
@@ -236,6 +239,9 @@ ScummToolsFrame::~ScummToolsFrame() {
for (std::vector<WizardPage *>::iterator iter = _pages.begin(); iter != _pages.end(); ++iter)
delete *iter;
for (std::vector<wxWindow *>::iterator iter = _oldPanels.begin(); iter != _oldPanels.end(); ++iter)
delete *iter;
}
void ScummToolsFrame::CreateMenuBar() {
@@ -288,9 +294,15 @@ void ScummToolsFrame::switchPage(WizardPage *next, SwitchToPage page) {
break;
}
if (oldPanel)
if (oldPanel) {
// Destroy the old page
oldPanel->Destroy();
// oldPanel->Destroy();
// We have an issue here for the intro page. This is called from the event handler of buttons on the panel
// (the Compress, Extract or Advanced button). So we cannot delete the oldPanel now (that would cause a crash).
// Instead we hide the panel and it will be deleted later (on the next Idel Event).
oldPanel->Hide();
_oldPanels.push_back(oldPanel);
}
wxWindow *newPanel = _pages.back()->CreatePanel(_wizardpane);
@@ -306,6 +318,13 @@ void ScummToolsFrame::switchPage(WizardPage *next, SwitchToPage page) {
_buttons->setPage(_pages.back(), newPanel);
}
void ScummToolsFrame::destroyOldPanels(wxIdleEvent &) {
while (!_oldPanels.empty()) {
delete _oldPanels.back();
_oldPanels.pop_back();
}
}
wxString ScummToolsFrame::GetHelpText() {
return _pages.back()->getHelp();
}
+3 -2
View File
@@ -115,8 +115,6 @@ public:
void onMenuAbout(wxCommandEvent &evt);
void onMenuExit(wxCommandEvent &evt);
/** The state of the wizard so far */
Configuration _configuration;
@@ -125,10 +123,13 @@ public:
private:
enum SwitchToPage { NextPage, PreviousPage, FirstPage };
void switchPage(WizardPage *nextPage, SwitchToPage page);
void destroyOldPanels(wxIdleEvent &evt);
wxPanel *_wizardpane;
std::vector<WizardPage *> _pages;
std::vector<wxWindow *> _oldPanels;
DECLARE_EVENT_TABLE()
};