Fixed crash on switching the application language.

This crash was caused by the RemovableDriveManager and 3DConnexion
detection services not being stopped correctly.
The fix executes all the tasks of the MainFrame at the language switch,
that are normally performed on application shut down.
This commit is contained in:
bubnikv 2020-03-07 12:24:40 +01:00
parent fb10e27778
commit d4ac4df21c
4 changed files with 49 additions and 59 deletions

View file

@ -433,46 +433,30 @@ float GUI_App::toolbar_icon_scale(const bool is_limited/* = false*/) const
void GUI_App::recreate_GUI() void GUI_App::recreate_GUI()
{ {
// Weird things happen as the Paint messages are floating around the windows being destructed. mainframe->shutdown();
// Avoid the Paint messages by hiding the main window.
// Also the application closes much faster without these unnecessary screen refreshes.
// In addition, there were some crashes due to the Paint events sent to already destructed windows.
mainframe->Show(false);
const auto msg_name = _(L("Changing of an application language")) + dots; const auto msg_name = _(L("Changing of an application language")) + dots;
wxProgressDialog dlg(msg_name, msg_name); wxProgressDialog dlg(msg_name, msg_name);
dlg.Pulse(); dlg.Pulse();
// to make sure nobody accesses data from the soon-to-be-destroyed widgets:
tabs_list.clear();
plater_ = nullptr;
dlg.Update(10, _(L("Recreating")) + dots); dlg.Update(10, _(L("Recreating")) + dots);
MainFrame* topwindow = mainframe; MainFrame *old_main_frame = mainframe;
mainframe = new MainFrame(); mainframe = new MainFrame();
sidebar().obj_list()->init_objects(); // propagate model objects to object list // Propagate model objects to object list.
sidebar().obj_list()->init_objects();
SetTopWindow(mainframe);
if (topwindow) { dlg.Update(30, _(L("Recreating")) + dots);
SetTopWindow(mainframe); old_main_frame->Destroy();
// For this moment ConfigWizard is deleted, invalidate it.
dlg.Update(30, _(L("Recreating")) + dots); m_wizard = nullptr;
topwindow->Destroy();
// For this moment ConfigWizard is deleted, invalidate it
m_wizard = nullptr;
}
dlg.Update(80, _(L("Loading of current presets")) + dots); dlg.Update(80, _(L("Loading of current presets")) + dots);
m_printhost_job_queue.reset(new PrintHostJobQueue(mainframe->printhost_queue_dlg())); m_printhost_job_queue.reset(new PrintHostJobQueue(mainframe->printhost_queue_dlg()));
load_current_presets(); load_current_presets();
mainframe->Show(true); mainframe->Show(true);
dlg.Update(90, _(L("Loading of a mode view")) + dots); dlg.Update(90, _(L("Loading of a mode view")) + dots);
/* Temporary workaround for the correct behavior of the Scrolled sidebar panel: /* Temporary workaround for the correct behavior of the Scrolled sidebar panel:
* change min hight of object list to the normal min value (15 * wxGetApp().em_unit()) * change min hight of object list to the normal min value (15 * wxGetApp().em_unit())
* after first whole Mainframe updating/layouting * after first whole Mainframe updating/layouting
@ -480,7 +464,6 @@ void GUI_App::recreate_GUI()
const int list_min_height = 15 * em_unit(); const int list_min_height = 15 * em_unit();
if (obj_list()->GetMinSize().GetY() > list_min_height) if (obj_list()->GetMinSize().GetY() > list_min_height)
obj_list()->SetMinSize(wxSize(-1, list_min_height)); obj_list()->SetMinSize(wxSize(-1, list_min_height));
update_mode(); update_mode();
// #ys_FIXME_delete_after_testing Do we still need this ? // #ys_FIXME_delete_after_testing Do we still need this ?
@ -575,7 +558,6 @@ void GUI_App::import_model(wxWindow *parent, wxArrayString& input_files) const
bool GUI_App::switch_language() bool GUI_App::switch_language()
{ {
if (select_language()) { if (select_language()) {
_3DScene::remove_all_canvases();
recreate_GUI(); recreate_GUI();
return true; return true;
} else { } else {

View file

@ -109,38 +109,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
event.Veto(); event.Veto();
return; return;
} }
this->shutdown();
if (m_plater)
m_plater->stop_jobs();
// Weird things happen as the Paint messages are floating around the windows being destructed.
// Avoid the Paint messages by hiding the main window.
// Also the application closes much faster without these unnecessary screen refreshes.
// In addition, there were some crashes due to the Paint events sent to already destructed windows.
this->Show(false);
// Stop the background thread (Windows and Linux).
// Disconnect from a 3DConnextion driver (OSX).
m_plater->get_mouse3d_controller().shutdown();
// Store the device parameter database back to appconfig.
m_plater->get_mouse3d_controller().save_config(*wxGetApp().app_config);
// Stop the background thread of the removable drive manager, so that no new updates will be sent to the Plater.
wxGetApp().removable_drive_manager()->shutdown();
// Save the slic3r.ini.Usually the ini file is saved from "on idle" callback,
// but in rare cases it may not have been called yet.
wxGetApp().app_config->save();
// if (m_plater)
// m_plater->print = undef;
_3DScene::remove_all_canvases();
// Slic3r::GUI::deregister_on_request_update_callback();
// set to null tabs and a plater
// to avoid any manipulations with them from App->wxEVT_IDLE after of the mainframe closing
wxGetApp().tabs_list.clear();
wxGetApp().plater_ = nullptr;
// propagate event // propagate event
event.Skip(); event.Skip();
}); });
@ -159,6 +128,41 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
m_plater->show_action_buttons(true); m_plater->show_action_buttons(true);
} }
// Called when closing the application and when switching the application language.
void MainFrame::shutdown()
{
if (m_plater)
m_plater->stop_jobs();
// Weird things happen as the Paint messages are floating around the windows being destructed.
// Avoid the Paint messages by hiding the main window.
// Also the application closes much faster without these unnecessary screen refreshes.
// In addition, there were some crashes due to the Paint events sent to already destructed windows.
this->Show(false);
// Stop the background thread (Windows and Linux).
// Disconnect from a 3DConnextion driver (OSX).
m_plater->get_mouse3d_controller().shutdown();
// Store the device parameter database back to appconfig.
m_plater->get_mouse3d_controller().save_config(*wxGetApp().app_config);
// Stop the background thread of the removable drive manager, so that no new updates will be sent to the Plater.
wxGetApp().removable_drive_manager()->shutdown();
// Save the slic3r.ini.Usually the ini file is saved from "on idle" callback,
// but in rare cases it may not have been called yet.
wxGetApp().app_config->save();
// if (m_plater)
// m_plater->print = undef;
_3DScene::remove_all_canvases();
// Slic3r::GUI::deregister_on_request_update_callback();
// set to null tabs and a plater
// to avoid any manipulations with them from App->wxEVT_IDLE after of the mainframe closing
wxGetApp().tabs_list.clear();
wxGetApp().plater_ = nullptr;
}
void MainFrame::update_title() void MainFrame::update_title()
{ {
wxString title = wxEmptyString; wxString title = wxEmptyString;

View file

@ -100,6 +100,9 @@ public:
MainFrame(); MainFrame();
~MainFrame() = default; ~MainFrame() = default;
// Called when closing the application and when switching the application language.
void shutdown();
Plater* plater() { return m_plater; } Plater* plater() { return m_plater; }
void update_title(); void update_title();

View file

@ -434,6 +434,7 @@ void RemovableDriveManager::shutdown()
#endif #endif
m_initialized = false; m_initialized = false;
m_callback_evt_handler = nullptr;
} }
bool RemovableDriveManager::set_and_verify_last_save_path(const std::string &path) bool RemovableDriveManager::set_and_verify_last_save_path(const std::string &path)