Fix a memory access bug in ObjectManipulation

This commit is contained in:
Vojtech Kral 2019-07-19 17:56:16 +02:00
parent 47df9506bb
commit 99e2fe20a5

View File

@ -199,18 +199,17 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
m_mirror_bitmap_off = ScalableBitmap(parent, "mirroring_off.png"); m_mirror_bitmap_off = ScalableBitmap(parent, "mirroring_off.png");
m_mirror_bitmap_hidden = ScalableBitmap(parent, "mirroring_transparent.png"); m_mirror_bitmap_hidden = ScalableBitmap(parent, "mirroring_transparent.png");
for (const std::string axis : { "x", "y", "z" }) { static const char axes[] = { 'X', 'Y', 'Z' };
const std::string label = boost::algorithm::to_upper_copy(axis); for (size_t axis_idx = 0; axis_idx < sizeof(axes); axis_idx++) {
def.set_default_value(new ConfigOptionString{ " " + label }); const char label = axes[axis_idx];
Option option = Option(def, axis + "_axis_legend"); def.set_default_value(new ConfigOptionString{ std::string(" ") + label });
Option option(def, std::string() + label + "_axis_legend");
unsigned int axis_idx = (axis[0] - 'x'); // 0, 1 or 2
// We will add a button to toggle mirroring to each axis: // We will add a button to toggle mirroring to each axis:
auto mirror_button = [this, mirror_btn_width, axis_idx, &label](wxWindow* parent) { auto mirror_button = [this, mirror_btn_width, axis_idx, label](wxWindow* parent) {
wxSize btn_size(em_unit(parent) * mirror_btn_width, em_unit(parent) * mirror_btn_width); wxSize btn_size(em_unit(parent) * mirror_btn_width, em_unit(parent) * mirror_btn_width);
auto btn = new ScalableButton(parent, wxID_ANY, "mirroring_off.png", wxEmptyString, btn_size, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER | wxTRANSPARENT_WINDOW); auto btn = new ScalableButton(parent, wxID_ANY, "mirroring_off.png", wxEmptyString, btn_size, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER | wxTRANSPARENT_WINDOW);
btn->SetToolTip(wxString::Format(_(L("Toggle %s axis mirroring")), label)); btn->SetToolTip(wxString::Format(_(L("Toggle %c axis mirroring")), (int)label));
m_mirror_buttons[axis_idx].first = btn; m_mirror_buttons[axis_idx].first = btn;
m_mirror_buttons[axis_idx].second = mbShown; m_mirror_buttons[axis_idx].second = mbShown;
@ -245,6 +244,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
canvas->do_mirror(L("Set Mirror")); canvas->do_mirror(L("Set Mirror"));
UpdateAndShow(true); UpdateAndShow(true);
}); });
return sizer; return sizer;
}; };