Rework destruction of FrameMain's children

wxCocoa doesn't like reparenting SubsGrid to NULL, so instead
recursively destroy all of FrameMain's children other than SubsGrid and
its parent. Fixes a crash on exit on OS X.

Originally committed to SVN as r6783.
This commit is contained in:
Thomas Goyne 2012-05-15 13:39:24 +00:00
parent 3a951a2564
commit ba413fa64d

View file

@ -223,25 +223,43 @@ FrameMain::FrameMain (wxArrayString args)
StartupLog("Leaving FrameMain constructor"); StartupLog("Leaving FrameMain constructor");
} }
FrameMain::~FrameMain () { /// @brief Delete everything but @a keep and its parents
// Because the subs grid is the selection controller, it needs to stay /// @param window Root window to delete the children of
// alive significantly longer than the other child controls /// @param keep Window to keep alive
SubsGrid->Reparent(0); /// @return Was @a keep found?
SubsGrid->Hide(); static bool delete_children(wxWindow *window, wxWindow *keep) {
bool found = false;
while (window->GetChildren().size() > (size_t)found) {
wxWindowList::iterator it = window->GetChildren().begin();
if (*it == keep)
found = true;
if (found) {
if (++it != window->GetChildren().end())
(*it)->wxWindowBase::Destroy();
}
else if (!delete_children(*it, keep))
(*it)->wxWindowBase::Destroy();
else
found = true;
}
return found;
}
FrameMain::~FrameMain () {
context->videoController->SetVideo(""); context->videoController->SetVideo("");
context->audioController->CloseAudio(); context->audioController->CloseAudio();
// Ensure the children get destroyed before the project context is destroyed // SubsGrid needs to be deleted last due to being the selection
DestroyChildren(); // controller, but everything else needs to be deleted before the context
wxTheApp->ProcessPendingEvents(); // is cleaned up
delete_children(this, SubsGrid);
delete context->ass; delete context->ass;
HelpButton::ClearPages(); HelpButton::ClearPages();
delete context->audioController; delete context->audioController;
delete context->local_scripts; delete context->local_scripts;
SubsGrid->Destroy();
} }
void FrameMain::InitToolbar() { void FrameMain::InitToolbar() {