Fix 1868911: exported canvases weren't being deleted, due to a handle never being...
[synfig.git] / synfig-studio / trunk / src / synfigapp / canvasinterface.cpp
index 87971c0..aa228eb 100644 (file)
@@ -193,6 +193,22 @@ CanvasInterface::add_layer_to(synfig::String name, synfig::Canvas::Handle canvas
                return 0;
        }
 
+       // automatically export the Index parameter of new Duplicate layers
+       if (name == "duplicate")
+               for (int i = 1; ; i++)
+               {
+                       String name = strprintf(_("Index %d"), i);
+                       try
+                       {
+                               canvas->find_value_node(name);
+                       }
+                       catch (Exception::IDNotFound x)
+                       {
+                               add_value_node(layer->dynamic_param_list().find("index")->second, name);
+                               break;
+                       }
+               }
+
        layer->set_canvas(canvas);
 
        // Apply some defaults
@@ -296,6 +312,7 @@ CanvasInterface::convert(ValueDesc value_desc, synfig::String type)
        action->set_param("canvas_interface",etl::loose_handle<CanvasInterface>(this));
        action->set_param("value_desc",value_desc);
        action->set_param("type",type);
+       action->set_param("time",get_time());
 
        if(!action->is_ready())
        {
@@ -360,7 +377,18 @@ CanvasInterface::generate_param_list(const ValueDesc &value_desc)
                param_list.add("value_node",value_desc.get_value_node());
 
        if(value_desc.is_const())
-               param_list.add("value",value_desc.get_value());
+       {
+               // Fix 1868911: if we put a ValueBase holding a Canvas handle
+               // into the param_list and then export the canvas, the handle
+               // will miss out of having its reference count reduced,
+               // because by the time the handle is destructed the canvas
+               // will no longer be inline.  So let's not propogate that
+               // ValueBase any further than here.
+               if (value_desc.get_value_type() == ValueBase::TYPE_CANVAS)
+                       param_list.add("value",Canvas::LooseHandle(value_desc.get_value().get(Canvas::LooseHandle())));
+               else
+                       param_list.add("value",value_desc.get_value());
+       }
 
        if(value_desc.parent_is_layer_param())
        {
@@ -542,14 +570,14 @@ CanvasInterface::import(const synfig::String &filename, bool /*copy*/)
                        {
                                x[0]=size[0];
                                x[1]=size[0]/w*h;
-                               if(size[0]<0 ^ size[1]<0)
+                               if((size[0]<0) ^ (size[1]<0))
                                        x[1]=-x[1];
                        }
                        else
                        {
                                x[1]=size[1];
                                x[0]=size[1]/h*w;
-                               if(size[0]<0 ^ size[1]<0)
+                               if((size[0]<0) ^ (size[1]<0))
                                        x[0]=-x[0];
                        }
                        if(!layer->set_param("tl",ValueBase(-x/2)))