Fixed some memory leaks related to heap-allocated wxDialogs

Some correctly destroyed dialogs were also converted to stack-allocated
This commit is contained in:
Lukas Matena 2019-08-15 12:52:56 +02:00
parent 15744f021a
commit c8ac46df43
4 changed files with 79 additions and 102 deletions

View file

@ -159,8 +159,8 @@ void Tab::create_preset_tab()
m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); }));
m_question_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent)
{
auto dlg = new ButtonsDescription(this, m_icon_descriptions);
if (dlg->ShowModal() == wxID_OK) {
ButtonsDescription dlg(this, m_icon_descriptions);
if (dlg.ShowModal() == wxID_OK) {
// Colors for ui "decoration"
for (Tab *tab : wxGetApp().tabs_list) {
tab->m_sys_label_clr = wxGetApp().get_label_clr_sys();
@ -1266,10 +1266,10 @@ void TabPrint::update()
if (m_config->opt_float("layer_height") < EPSILON)
{
const wxString msg_text = _(L("Zero layer height is not valid.\n\nThe layer height will be reset to 0.01."));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Layer height")), wxICON_WARNING | wxOK);
wxMessageDialog dialog(parent(), msg_text, _(L("Layer height")), wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *m_config;
is_msg_dlg_already_exist = true;
dialog->ShowModal();
dialog.ShowModal();
new_conf.set_key_value("layer_height", new ConfigOptionFloat(0.01));
load_config(new_conf);
is_msg_dlg_already_exist = false;
@ -1278,10 +1278,10 @@ void TabPrint::update()
if (fabs(m_config->option<ConfigOptionFloatOrPercent>("first_layer_height")->value - 0) < EPSILON)
{
const wxString msg_text = _(L("Zero first layer height is not valid.\n\nThe first layer height will be reset to 0.01."));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("First layer height")), wxICON_WARNING | wxOK);
wxMessageDialog dialog(parent(), msg_text, _(L("First layer height")), wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *m_config;
is_msg_dlg_already_exist = true;
dialog->ShowModal();
dialog.ShowModal();
new_conf.set_key_value("first_layer_height", new ConfigOptionFloatOrPercent(0.01, false));
load_config(new_conf);
is_msg_dlg_already_exist = false;
@ -1299,9 +1299,9 @@ void TabPrint::update()
"- no support material\n"
"- no ensure_vertical_shell_thickness\n"
"\nShall I adjust those settings in order to enable Spiral Vase?"));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Spiral Vase")), wxICON_WARNING | wxYES | wxNO);
wxMessageDialog dialog(parent(), msg_text, _(L("Spiral Vase")), wxICON_WARNING | wxYES | wxNO);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_YES) {
if (dialog.ShowModal() == wxID_YES) {
new_conf.set_key_value("perimeters", new ConfigOptionInt(1));
new_conf.set_key_value("top_solid_layers", new ConfigOptionInt(0));
new_conf.set_key_value("fill_density", new ConfigOptionPercent(0));
@ -1324,9 +1324,9 @@ void TabPrint::update()
"if they are printed with the current extruder without triggering a tool change.\n"
"(both support_material_extruder and support_material_interface_extruder need to be set to 0).\n"
"\nShall I adjust those settings in order to enable the Wipe Tower?"));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Wipe Tower")), wxICON_WARNING | wxYES | wxNO);
wxMessageDialog dialog(parent(), msg_text, _(L("Wipe Tower")), wxICON_WARNING | wxYES | wxNO);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_YES) {
if (dialog.ShowModal() == wxID_YES) {
new_conf.set_key_value("support_material_extruder", new ConfigOptionInt(0));
new_conf.set_key_value("support_material_interface_extruder", new ConfigOptionInt(0));
}
@ -1341,9 +1341,9 @@ void TabPrint::update()
wxString msg_text = _(L("For the Wipe Tower to work with the soluble supports, the support layers\n"
"need to be synchronized with the object layers.\n"
"\nShall I synchronize support layers in order to enable the Wipe Tower?"));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Wipe Tower")), wxICON_WARNING | wxYES | wxNO);
wxMessageDialog dialog(parent(), msg_text, _(L("Wipe Tower")), wxICON_WARNING | wxYES | wxNO);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_YES) {
if (dialog.ShowModal() == wxID_YES) {
new_conf.set_key_value("support_material_synchronize_layers", new ConfigOptionBool(true));
}
else
@ -1359,9 +1359,9 @@ void TabPrint::update()
wxString msg_text = _(L("Supports work better, if the following feature is enabled:\n"
"- Detect bridging perimeters\n"
"\nShall I adjust those settings for supports?"));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Support Generator")), wxICON_WARNING | wxYES | wxNO | wxCANCEL);
wxMessageDialog dialog(parent(), msg_text, _(L("Support Generator")), wxICON_WARNING | wxYES | wxNO | wxCANCEL);
DynamicPrintConfig new_conf = *m_config;
auto answer = dialog->ShowModal();
auto answer = dialog.ShowModal();
if (answer == wxID_YES) {
// Enable "detect bridging perimeters".
new_conf.set_key_value("overhangs", new ConfigOptionBool(true));
@ -1403,9 +1403,9 @@ void TabPrint::update()
if (!correct_100p_fill) {
wxString msg_text = GUI::from_u8((boost::format(_utf8(L("The %1% infill pattern is not supposed to work at 100%% density.\n\n"
"Shall I switch to rectilinear fill pattern?"))) % str_fill_pattern).str());
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Infill")), wxICON_WARNING | wxYES | wxNO);
wxMessageDialog dialog(parent(), msg_text, _(L("Infill")), wxICON_WARNING | wxYES | wxNO);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_YES) {
if (dialog.ShowModal() == wxID_YES) {
new_conf.set_key_value("fill_pattern", new ConfigOptionEnum<InfillPattern>(ipRectilinear));
fill_density = 100;
}
@ -2045,10 +2045,10 @@ void TabPrinter::build_fff()
const wxString msg_text = _(L("Single Extruder Multi Material is selected, \n"
"and all extruders must have the same diameter.\n"
"Do you want to change the diameter for all extruders to first extruder nozzle diameter value?"));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Nozzle diameter")), wxICON_WARNING | wxYES_NO);
wxMessageDialog dialog(parent(), msg_text, _(L("Nozzle diameter")), wxICON_WARNING | wxYES_NO);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_YES) {
if (dialog.ShowModal() == wxID_YES) {
for (size_t i = 1; i < nozzle_diameters.size(); i++)
nozzle_diameters[i] = frst_diam;
@ -2507,10 +2507,10 @@ void TabPrinter::build_unregular_pages()
{
const wxString msg_text = _(L("This is a single extruder multimaterial printer, diameters of all extruders "
"will be set to the new value. Do you want to proceed?"));
auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Nozzle diameter")), wxICON_WARNING | wxYES_NO);
wxMessageDialog dialog(parent(), msg_text, _(L("Nozzle diameter")), wxICON_WARNING | wxYES_NO);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_YES) {
if (dialog.ShowModal() == wxID_YES) {
for (size_t i = 0; i < nozzle_diameters.size(); i++) {
if (i==extruder_idx)
continue;
@ -2715,13 +2715,13 @@ void TabPrinter::update_fff()
get_field("retract_before_wipe", i)->toggle(wipe);
if (use_firmware_retraction && wipe) {
auto dialog = new wxMessageDialog(parent(),
wxMessageDialog dialog(parent(),
_(L("The Wipe option is not available when using the Firmware Retraction mode.\n"
"\nShall I disable it in order to enable Firmware Retraction?")),
_(L("Firmware Retraction")), wxICON_WARNING | wxYES | wxNO);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_YES) {
if (dialog.ShowModal() == wxID_YES) {
auto wipe = static_cast<ConfigOptionBools*>(m_config->option("wipe")->clone());
for (int w = 0; w < wipe->values.size(); w++)
wipe->values[w] = false;
@ -3073,10 +3073,10 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr
message += wxString("\n") + tab + from_u8(new_printer_name) + "\n\n";
message += _(L("and it has the following unsaved changes:"));
}
auto confirm = new wxMessageDialog(parent(),
wxMessageDialog confirm(parent(),
message + "\n" + changes + "\n\n" + _(L("Discard changes and continue anyway?")),
_(L("Unsaved Changes")), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
return confirm->ShowModal() == wxID_YES;
return confirm.ShowModal() == wxID_YES;
}
// If we are switching from the FFF-preset to the SLA, we should to control the printed objects if they have a part(s).
@ -3183,11 +3183,11 @@ void Tab::save_preset(std::string name /*= ""*/)
values.push_back(preset.name);
}
auto dlg = new SavePresetWindow(parent());
dlg->build(title(), default_name, values);
if (dlg->ShowModal() != wxID_OK)
SavePresetWindow dlg(parent());
dlg.build(title(), default_name, values);
if (dlg.ShowModal() != wxID_OK)
return;
name = dlg->get_name();
name = dlg.get_name();
if (name == "") {
show_error(this, _(L("The supplied name is empty. It can't be saved.")));
return;
@ -3799,13 +3799,13 @@ void TabSLAPrint::update()
wxString msg_text = _(
L("Head penetration should not be greater than the head width."));
auto dialog = new wxMessageDialog(parent(),
msg_text,
_(L("Invalid Head penetration")),
wxICON_WARNING | wxOK);
wxMessageDialog dialog(parent(),
msg_text,
_(L("Invalid Head penetration")),
wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_OK) {
if (dialog.ShowModal() == wxID_OK) {
new_conf.set_key_value("support_head_penetration",
new ConfigOptionFloat(head_width));
}
@ -3819,13 +3819,13 @@ void TabSLAPrint::update()
wxString msg_text = _(L(
"Pinhead diameter should be smaller than the pillar diameter."));
auto dialog = new wxMessageDialog(parent(),
msg_text,
_(L("Invalid pinhead diameter")),
wxICON_WARNING | wxOK);
wxMessageDialog dialog (parent(),
msg_text,
_(L("Invalid pinhead diameter")),
wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *m_config;
if (dialog->ShowModal() == wxID_OK) {
if (dialog.ShowModal() == wxID_OK) {
new_conf.set_key_value("support_head_front_diameter",
new ConfigOptionFloat(pillar_d / 2.0));
}