From: dooglus Date: Fri, 14 Nov 2008 21:14:21 +0000 (+0000) Subject: Fix 1814151: "Add a layer inside an exported canvas crash". Check the return value... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=04295e119995f2bf29f75be0d0aec22e93bc0fad;p=synfig.git Fix 1814151: "Add a layer inside an exported canvas crash". Check the return value of add_layer_to() in lots of places. There may be more to come, and the function itself looks like it needs attention too. git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2201 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-studio/trunk/src/gtkmm/state_bline.cpp b/synfig-studio/trunk/src/gtkmm/state_bline.cpp index 19a41c2..b9de1fe 100644 --- a/synfig-studio/trunk/src/gtkmm/state_bline.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_bline.cpp @@ -621,7 +621,11 @@ StateBLine_Context::run_() synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth)); - assert(layer); + if (!layer) + { + group.cancel(); + throw String(_("Unable to create layer")); + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Gradient")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -680,7 +684,11 @@ StateBLine_Context::run_() synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth)); - assert(layer); + if (!layer) + { + group.cancel(); + throw String(_("Unable to create layer")); + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Plant")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -739,7 +747,11 @@ StateBLine_Context::run_() synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth)); - assert(layer); + if (!layer) + { + group.cancel(); + throw String(_("Unable to create layer")); + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Region")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -809,7 +821,11 @@ StateBLine_Context::run_() synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth)); - assert(layer); + if (!layer) + { + group.cancel(); + throw String(_("Unable to create layer")); + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Outline")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); diff --git a/synfig-studio/trunk/src/gtkmm/state_circle.cpp b/synfig-studio/trunk/src/gtkmm/state_circle.cpp index 59db4d5..00c8d02 100644 --- a/synfig-studio/trunk/src/gtkmm/state_circle.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_circle.cpp @@ -601,6 +601,12 @@ StateCircle_Context::make_circle(const Point& _p1, const Point& _p2) get_falloff() >= 0 && get_falloff() < CIRCLE_NUM_FALLOFF) { layer=get_canvas_interface()->add_layer_to("circle",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_param("origin",p1); @@ -670,7 +676,12 @@ StateCircle_Context::make_circle(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Gradient")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -739,7 +750,12 @@ StateCircle_Context::make_circle(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Plant")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -808,7 +824,12 @@ StateCircle_Context::make_circle(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Region")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -886,7 +907,12 @@ StateCircle_Context::make_circle(const Point& _p1, const Point& _p2) if (get_layer_outline_flag()) { Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Outline")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); diff --git a/synfig-studio/trunk/src/gtkmm/state_draw.cpp b/synfig-studio/trunk/src/gtkmm/state_draw.cpp index b1123b5..1d5666c 100644 --- a/synfig-studio/trunk/src/gtkmm/state_draw.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_draw.cpp @@ -115,7 +115,7 @@ class studio::StateDraw_Context : public sigc::trackable Duckmatic::Type old_duckmask; void fill_last_stroke(); - void fill_last_stroke_and_unselect_other_layers(); + Smach::event_result fill_last_stroke_and_unselect_other_layers(); Smach::event_result new_bline(std::list bline,bool loop_bline_flag,float radius); @@ -1038,7 +1038,15 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline // fill_last_stroke() will take care of clearing the selection if we're calling it if(get_outline_flag() && get_region_flag()) - fill_last_stroke_and_unselect_other_layers(); + { + if (fill_last_stroke_and_unselect_other_layers() == Smach::RESULT_ERROR) + { + get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list); + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return Smach::RESULT_ERROR; + } + } else get_canvas_interface()->get_selection_manager()->clear_selected_layers(); @@ -1050,11 +1058,25 @@ StateDraw_Context::new_bline(std::list bline,bool loop_bline if(get_outline_flag()) { layer=get_canvas_interface()->add_layer_to("outline",canvas,depth); + if (!layer) + { + get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list); + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return Smach::RESULT_ERROR; + } layer->set_description(get_id()+_(" Outline")); } else { layer=get_canvas_interface()->add_layer_to("region",canvas,depth); + if (!layer) + { + get_canvas_view()->get_selection_manager()->set_selected_layers(layer_list); + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return Smach::RESULT_ERROR; + } layer->set_description(get_id()+_(" Region")); } @@ -1774,7 +1796,12 @@ StateDraw_Context::new_region(std::list bline, synfig::Real synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); layer=get_canvas_interface()->add_layer_to("region",canvas,depth); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return Smach::RESULT_ERROR; + } layer->set_param("color",synfigapp::Main::get_background_color()); if(get_feather()) { @@ -1946,11 +1973,11 @@ StateDraw_Context::reverse_bline(std::list &bline) } } -void +Smach::event_result StateDraw_Context::fill_last_stroke_and_unselect_other_layers() { if(!last_stroke) - return; + return Smach::RESULT_OK; synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Fill Stroke")); @@ -1972,7 +1999,7 @@ StateDraw_Context::fill_last_stroke_and_unselect_other_layers() get_canvas_interface()->get_selection_manager()->clear_selected_layers(); layer=get_canvas_interface()->add_layer_to("region", canvas, depth); - assert(layer); + if (!layer) return Smach::RESULT_ERROR; layer->set_param("color",synfigapp::Main::get_background_color()); layer->set_description(last_stroke_id + _(" Region")); @@ -1992,9 +2019,10 @@ StateDraw_Context::fill_last_stroke_and_unselect_other_layers() { get_canvas_view()->get_ui_interface()->error(_("Unable to create Region layer")); group.cancel(); - return; + return Smach::RESULT_OK; } get_canvas_view()->get_selection_manager()->set_selected_layer(layer); + return Smach::RESULT_OK; } void diff --git a/synfig-studio/trunk/src/gtkmm/state_gradient.cpp b/synfig-studio/trunk/src/gtkmm/state_gradient.cpp index f116265..c8461b5 100644 --- a/synfig-studio/trunk/src/gtkmm/state_gradient.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_gradient.cpp @@ -404,6 +404,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) case GRADIENT_INTERPOLATION_LINEAR: layer=get_canvas_interface()->add_layer_to("linear_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("p1",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"p1"); layer->set_param("p2",p2); @@ -411,6 +417,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) break; case GRADIENT_RADIAL: layer=get_canvas_interface()->add_layer_to("radial_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("center",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"center"); layer->set_param("radius",(p2-p1).mag()); @@ -418,6 +430,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) break; case GRADIENT_CONICAL: layer=get_canvas_interface()->add_layer_to("conical_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("center",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"center"); { @@ -428,6 +446,12 @@ StateGradient_Context::make_gradient(const Point& _p1, const Point& _p2) break; case GRADIENT_SPIRAL: layer=get_canvas_interface()->add_layer_to("spiral_gradient",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer->set_param("center",p1); get_canvas_interface()->signal_layer_param_changed()(layer,"center"); layer->set_param("radius",(p2-p1).mag()); diff --git a/synfig-studio/trunk/src/gtkmm/state_polygon.cpp b/synfig-studio/trunk/src/gtkmm/state_polygon.cpp index 494928e..259089f 100644 --- a/synfig-studio/trunk/src/gtkmm/state_polygon.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_polygon.cpp @@ -531,6 +531,12 @@ StatePolygon_Context::run() if (get_layer_polygon_flag()) { layer=get_canvas_interface()->add_layer_to("polygon",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_param("invert",get_invert()); @@ -609,7 +615,12 @@ StatePolygon_Context::run() synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Gradient")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -668,7 +679,12 @@ StatePolygon_Context::run() synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Plant")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -727,7 +743,12 @@ StatePolygon_Context::run() synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Region")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -795,7 +816,12 @@ StatePolygon_Context::run() if (get_layer_outline_flag()) { Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Outline")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); diff --git a/synfig-studio/trunk/src/gtkmm/state_rectangle.cpp b/synfig-studio/trunk/src/gtkmm/state_rectangle.cpp index d01a943..ce96b38 100644 --- a/synfig-studio/trunk/src/gtkmm/state_rectangle.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_rectangle.cpp @@ -519,6 +519,12 @@ StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2) if (get_layer_rectangle_flag()) { layer=get_canvas_interface()->add_layer_to("rectangle",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_param("point1",p1); @@ -552,7 +558,12 @@ StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Gradient")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -611,7 +622,12 @@ StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Plant")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -670,7 +686,12 @@ StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Region")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -738,7 +759,12 @@ StateRectangle_Context::make_rectangle(const Point& _p1, const Point& _p2) if (get_layer_outline_flag()) { Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Outline")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); diff --git a/synfig-studio/trunk/src/gtkmm/state_star.cpp b/synfig-studio/trunk/src/gtkmm/state_star.cpp index 64bacd9..8b5c14f 100644 --- a/synfig-studio/trunk/src/gtkmm/state_star.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_star.cpp @@ -634,6 +634,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) if (get_layer_star_flag()) { layer=get_canvas_interface()->add_layer_to("star",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_param("origin",p1); @@ -707,7 +713,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("curve_gradient",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Gradient")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -771,7 +782,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("plant",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Plant")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -835,7 +851,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) synfigapp::PushMode push_mode(get_canvas_interface(),synfigapp::MODE_NORMAL); Layer::Handle layer(get_canvas_interface()->add_layer_to("region",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Region")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); @@ -908,7 +929,12 @@ StateStar_Context::make_star(const Point& _p1, const Point& _p2) if (get_layer_outline_flag()) { Layer::Handle layer(get_canvas_interface()->add_layer_to("outline",canvas,depth)); - assert(layer); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_description(get_id()+_(" Outline")); get_canvas_interface()->signal_layer_new_description()(layer,layer->get_description()); diff --git a/synfig-studio/trunk/src/gtkmm/state_text.cpp b/synfig-studio/trunk/src/gtkmm/state_text.cpp index cac8cfc..8f7d0c9 100644 --- a/synfig-studio/trunk/src/gtkmm/state_text.cpp +++ b/synfig-studio/trunk/src/gtkmm/state_text.cpp @@ -400,6 +400,12 @@ StateText_Context::make_text(const Point& _point) App::dialog_entry(_("Text Entry"), _("Enter text here:"), text); layer=get_canvas_interface()->add_layer_to("text",canvas,depth); + if (!layer) + { + get_canvas_view()->get_ui_interface()->error(_("Unable to create layer")); + group.cancel(); + return; + } layer_selection.push_back(layer); layer->set_param("origin",point);