diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 40d818e93..47b49748d 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -433,46 +433,30 @@ float GUI_App::toolbar_icon_scale(const bool is_limited/* = false*/) const void GUI_App::recreate_GUI() { - // 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. - mainframe->Show(false); + mainframe->shutdown(); const auto msg_name = _(L("Changing of an application language")) + dots; wxProgressDialog dlg(msg_name, msg_name); 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); - MainFrame* topwindow = mainframe; + MainFrame *old_main_frame = 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) { - SetTopWindow(mainframe); - - dlg.Update(30, _(L("Recreating")) + dots); - topwindow->Destroy(); - - // For this moment ConfigWizard is deleted, invalidate it - m_wizard = nullptr; - } + dlg.Update(30, _(L("Recreating")) + dots); + old_main_frame->Destroy(); + // For this moment ConfigWizard is deleted, invalidate it. + m_wizard = nullptr; dlg.Update(80, _(L("Loading of current presets")) + dots); - m_printhost_job_queue.reset(new PrintHostJobQueue(mainframe->printhost_queue_dlg())); - load_current_presets(); - mainframe->Show(true); dlg.Update(90, _(L("Loading of a mode view")) + dots); - /* 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()) * after first whole Mainframe updating/layouting @@ -480,7 +464,6 @@ void GUI_App::recreate_GUI() const int list_min_height = 15 * em_unit(); if (obj_list()->GetMinSize().GetY() > list_min_height) obj_list()->SetMinSize(wxSize(-1, list_min_height)); - update_mode(); // #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() { if (select_language()) { - _3DScene::remove_all_canvases(); recreate_GUI(); return true; } else { diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 0d1623178..defd0b53a 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -109,38 +109,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S event.Veto(); return; } - - 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; - + this->shutdown(); // propagate event event.Skip(); }); @@ -159,6 +128,41 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S 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() { wxString title = wxEmptyString; diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 20e18fc53..2ccd77666 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -100,6 +100,9 @@ public: MainFrame(); ~MainFrame() = default; + // Called when closing the application and when switching the application language. + void shutdown(); + Plater* plater() { return m_plater; } void update_title(); diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index a363d8ae8..2264cc954 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -434,6 +434,7 @@ void RemovableDriveManager::shutdown() #endif m_initialized = false; + m_callback_evt_handler = nullptr; } bool RemovableDriveManager::set_and_verify_last_save_path(const std::string &path)