From 025a508de21a3e3b1c581229e11d68a718566ae2 Mon Sep 17 00:00:00 2001
From: Alessandro Ranellucci <aar@cpan.org>
Date: Sat, 19 Dec 2015 20:41:47 +0100
Subject: [PATCH] Ignore cut result if user didn't click the cut button

---
 lib/Slic3r/GUI/Plater.pm                 | 2 +-
 lib/Slic3r/GUI/Plater/ObjectCutDialog.pm | 7 +------
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm
index ec9ea2e14..09d15886d 100644
--- a/lib/Slic3r/GUI/Plater.pm
+++ b/lib/Slic3r/GUI/Plater.pm
@@ -1541,7 +1541,7 @@ sub object_cut_dialog {
 		object              => $self->{objects}[$obj_idx],
 		model_object        => $self->{model}->objects->[$obj_idx],
 	);
-	$dlg->ShowModal;
+	return unless $dlg->ShowModal == wxID_OK;
 	
 	if (my @new_objects = $dlg->NewModelObjects) {
 	    $self->remove($obj_idx);
diff --git a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm
index ad4ab9221..e7f0629e7 100644
--- a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm
+++ b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm
@@ -111,14 +111,9 @@ sub new {
     $self->SetMinSize($self->GetSize);
     $self->{sizer}->SetSizeHints($self);
     
-    # needed to actually free memory
-    EVT_CLOSE($self, sub {
-        $self->EndModal(wxID_OK);
-        $self->Destroy;
-    });
-    
     EVT_BUTTON($self, $self->{btn_cut}, sub {
         $self->perform_cut(1);
+        $self->EndModal(wxID_OK);
         $self->Close;
     });