Fix crash on Linux when switching between tabs in printer config (#6437)

* Fix crash due to the wrong window get returned in `PointCtrl` (SoftFever/OrcaSlicer#6261).
`getWindow()` must return the control itself, not its child control; otherwise the child control will be destroyed twice when the tab container is destroyed.

* Fix another crash on Linux caused by unused undo button
This commit is contained in:
Noisyfox 2024-08-18 16:30:45 +08:00 committed by GitHub
parent 01b16814ad
commit 4dd7d79d76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 5 deletions

View file

@ -1944,6 +1944,7 @@ void PointCtrl::BUILD()
y_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { e.Skip(); propagate_value(y_textctrl); }), y_textctrl->GetId()); y_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { e.Skip(); propagate_value(y_textctrl); }), y_textctrl->GetId());
// // recast as a wxWindow to fit the calling convention // // recast as a wxWindow to fit the calling convention
window = dynamic_cast<wxWindow*>(x_input);
sizer = dynamic_cast<wxSizer*>(temp); sizer = dynamic_cast<wxSizer*>(temp);
x_textctrl->SetToolTip(get_tooltip_text(X+", "+Y)); x_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));

View file

@ -506,6 +506,7 @@ public:
TextInput* x_input{nullptr}; TextInput* x_input{nullptr};
TextInput* y_input{nullptr}; TextInput* y_input{nullptr};
wxWindow* window{nullptr};
void BUILD() override; void BUILD() override;
bool value_was_changed(wxTextCtrl* win); bool value_was_changed(wxTextCtrl* win);
// Propagate value from field to the OptionGroupe and Config after kill_focus/ENTER // Propagate value from field to the OptionGroupe and Config after kill_focus/ENTER
@ -524,7 +525,7 @@ public:
x_textctrl->Disable(); x_textctrl->Disable();
y_textctrl->Disable(); } y_textctrl->Disable(); }
wxSizer* getSizer() override { return sizer; } wxSizer* getSizer() override { return sizer; }
wxWindow* getWindow() override { return dynamic_cast<wxWindow*>(x_textctrl); } wxWindow* getWindow() override { return window; }
}; };
class StaticText : public Field { class StaticText : public Field {

View file

@ -266,7 +266,7 @@ void Tab::create_preset_tab()
set_tooltips_text(); set_tooltips_text();
add_scaled_button(m_top_panel, &m_undo_btn, m_bmp_white_bullet.name()); add_scaled_button(m_top_panel, &m_undo_btn, m_bmp_white_bullet.name());
add_scaled_button(m_top_panel, &m_undo_to_sys_btn, m_bmp_white_bullet.name()); //add_scaled_button(m_top_panel, &m_undo_to_sys_btn, m_bmp_white_bullet.name());
add_scaled_button(m_top_panel, &m_btn_search, "search"); add_scaled_button(m_top_panel, &m_btn_search, "search");
m_btn_search->SetToolTip(_L("Search in preset")); m_btn_search->SetToolTip(_L("Search in preset"));
@ -347,7 +347,7 @@ void Tab::create_preset_tab()
}); });
m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(); })); m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(); }));
m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); })); //m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); }));
/* m_search_btn->Bind(wxEVT_BUTTON, [](wxCommandEvent) { wxGetApp().plater()->search(false); });*/ /* m_search_btn->Bind(wxEVT_BUTTON, [](wxCommandEvent) { wxGetApp().plater()->search(false); });*/
// Colors for ui "decoration" // Colors for ui "decoration"
@ -1034,10 +1034,10 @@ void Tab::update_undo_buttons()
{ {
// BBS: restore all pages in preset // BBS: restore all pages in preset
m_undo_btn-> SetBitmap_(m_presets->get_edited_preset().is_dirty ? m_bmp_value_revert: m_bmp_white_bullet); m_undo_btn-> SetBitmap_(m_presets->get_edited_preset().is_dirty ? m_bmp_value_revert: m_bmp_white_bullet);
m_undo_to_sys_btn-> SetBitmap_(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock); //m_undo_to_sys_btn-> SetBitmap_(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock);
m_undo_btn->SetToolTip(m_presets->get_edited_preset().is_dirty ? _L("Click to reset all settings to the last saved preset.") : m_ttg_white_bullet); m_undo_btn->SetToolTip(m_presets->get_edited_preset().is_dirty ? _L("Click to reset all settings to the last saved preset.") : m_ttg_white_bullet);
m_undo_to_sys_btn->SetToolTip(m_is_nonsys_values ? *m_ttg_non_system : m_ttg_value_lock); //m_undo_to_sys_btn->SetToolTip(m_is_nonsys_values ? *m_ttg_non_system : m_ttg_value_lock);
} }
void Tab::on_roll_back_value(const bool to_sys /*= true*/) void Tab::on_roll_back_value(const bool to_sys /*= true*/)