From ea163edc41f1e3394e89bd187b25c338418e1433 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Sun, 5 Aug 2018 23:36:25 +0200 Subject: [PATCH] Deregister the update callback on end of the application. This fixes a crash on exit. --- lib/Slic3r/GUI/MainFrame.pm | 1 + lib/Slic3r/GUI/Plater.pm | 7 +------ xs/src/slic3r/GUI/GUI.cpp | 5 ----- xs/src/slic3r/GUI/GUI.hpp | 2 +- xs/xsp/GUI.xsp | 14 ++++++-------- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 77d7956c9..6baefa545 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -107,6 +107,7 @@ sub new { wxTheApp->{app_config}->save; $self->{plater}->{print} = undef if($self->{plater}); Slic3r::GUI::_3DScene::remove_all_canvases(); + Slic3r::GUI::deregister_on_request_update_callback(); # propagate event $event->Skip; }); diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 340807f5f..adaf101fb 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -145,11 +145,6 @@ sub new { $self->rotate(rad2deg($angle_z), Z, 'absolute'); }; - # callback to call schedule_background_process - my $on_request_update = sub { - $self->schedule_background_process; - }; - # callback to update object's geometry info while using gizmos my $on_update_geometry_info = sub { my ($size_x, $size_y, $size_z, $scale_factor) = @_; @@ -208,7 +203,7 @@ sub new { Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{canvas3D}, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{preview3D}->canvas, $self->{canvas3D}); }); } - Slic3r::_GUI::register_on_request_update_callback($on_request_update); + Slic3r::GUI::register_on_request_update_callback(sub { $self->schedule_background_process; }); # # Initialize 2D preview canvas # $self->{canvas} = Slic3r::GUI::Plater::2D->new($self->{preview_notebook}, wxDefaultSize, $self->{objects}, $self->{model}, $self->{config}); diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 8f3c8144c..8cd7ed776 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -920,11 +920,6 @@ ConfigOptionsGroup* get_optgroup() return m_optgroup.get(); } -void register_on_request_update_callback(void* callback) { - if (callback != nullptr) - g_on_request_update_callback.register_callback(callback); -} - wxButton* get_wiping_dialog_button() { return g_wiping_dialog_button; diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index c41ba2521..165288819 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -172,8 +172,8 @@ wxString from_u8(const std::string &str); void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFlexGridSizer* preset_sizer); +// Callback to trigger a configuration update timer on the Plater. static PerlCallback g_on_request_update_callback; -void register_on_request_update_callback(void* callback); ConfigOptionsGroup* get_optgroup(); wxButton* get_wiping_dialog_button(); diff --git a/xs/xsp/GUI.xsp b/xs/xsp/GUI.xsp index 7872abc80..c6eead1ad 100644 --- a/xs/xsp/GUI.xsp +++ b/xs/xsp/GUI.xsp @@ -105,11 +105,9 @@ void fix_model_by_win10_sdk_gui(ModelObject *model_object_src, Print *print, Mod void set_3DScene(SV *scene) %code%{ Slic3r::GUI::set_3DScene((_3DScene *)wxPli_sv_2_object(aTHX_ scene, "Slic3r::Model::3DScene") ); %}; -%package{Slic3r::_GUI}; -%{ -void -register_on_request_update_callback(callback) - SV *callback; - CODE: - Slic3r::GUI::register_on_request_update_callback((void*)callback); -%} +void register_on_request_update_callback(SV* callback) + %code%{ Slic3r::GUI::g_on_request_update_callback.register_callback(callback); %}; + +void deregister_on_request_update_callback() + %code%{ Slic3r::GUI::g_on_request_update_callback.deregister_callback(); %}; +