Fix non-regression test for bug #2165. No more generate an error when saving a "no... 26/10926/2
Vincent COUVERT [Thu, 21 Mar 2013 12:43:12 +0000 (13:43 +0100)]
To test: test_run("graphics" ,"bug_2165")

Change-Id: Ibc9a45f3f9adea8b4df0dffdae58486cc128ca18

scilab/modules/io/macros/%_save.sci

index 27f33f8..5b55d0f 100644 (file)
@@ -1,10 +1,10 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
-// 
+//
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
 // you should have received as part of this distribution.  The terms
-// are also available at    
+// are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 //2012/08/06 transform macros to string to save it
@@ -43,36 +43,46 @@ function [] = %_save(%__filename__, varargin)
     endfunction
 
     function result = inspectList(l)
-    if typeof(l)=="list" then
-        result = list();
-        for %__i__ = definedfields(l)
-            if typeof(l(%__i__)) == "handle" then
-                result(%__i__) = extractMatrixHandle(l(%__i__));
-            elseif isMacro(l(%__i__)) | isCompiledMacro(l(%__i__)) then
-                //build an arbitrary name to the macro
-                result(%__i__) = extractMacro(l(%__i__), "function");
-            elseif isList(l(%__i__)) then
-                result(%__i__) = inspectList(l(%__i__));
-            else
-                result(%__i__) = l(%__i__);
+        if typeof(l)=="list" then
+            result = list();
+            for %__i__ = definedfields(l)
+                if typeof(l(%__i__)) == "handle" then
+                    if ~is_handle_valid(l(%__i__)) then
+                        oldMode = warning("query");
+                        warning("on");
+                        warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save"));
+                        warning(oldMode);
+                        result(%__i__) = [];
+                    else
+                        result(%__i__) = extractMatrixHandle(l(%__i__));
+                    end
+                elseif isMacro(l(%__i__)) | isCompiledMacro(l(%__i__)) then
+                    //build an arbitrary name to the macro
+                    result(%__i__) = extractMacro(l(%__i__), "function");
+                elseif isList(l(%__i__)) then
+                    result(%__i__) = inspectList(l(%__i__));
+                elseif type(l(%__i__)) == 14 then //library, must not be save
+                    result(%__i__) = [];
+                else
+                    result(%__i__) = l(%__i__);
+                end
             end
-        end
-    else
-        fieldNb = size(getfield(1, l), "*");
-        for kField = 2:fieldNb // Do not inspect first field (field names)
-            fieldValue = getfield(kField, l);
-            if typeof(fieldValue) == "handle" then
-                fieldValue = extractMatrixHandle(fieldValue);
-            elseif isMacro(fieldValue) | isCompiledMacro(fieldValue) then
-                //build an arbitrary name to the macro
-                fieldValue = extractMacro(fieldValue, "function");
-            elseif isList(fieldValue) then
-                fieldValue = inspectList(fieldValue);
+        else
+            fieldNb = size(getfield(1, l), "*");
+            for kField = 2:fieldNb // Do not inspect first field (field names)
+                fieldValue = getfield(kField, l);
+                if typeof(fieldValue) == "handle" then
+                    fieldValue = extractMatrixHandle(fieldValue);
+                elseif isMacro(fieldValue) | isCompiledMacro(fieldValue) then
+                    //build an arbitrary name to the macro
+                    fieldValue = extractMacro(fieldValue, "function");
+                elseif isList(fieldValue) then
+                    fieldValue = inspectList(fieldValue);
+                end
+                setfield(kField, fieldValue, l);
             end
-            setfield(kField, fieldValue, l);
+            result = l;
         end
-        result = l;
-    end
     endfunction
 
     function matrixHandle = extractMatrixHandle(h)
@@ -87,7 +97,7 @@ function [] = %_save(%__filename__, varargin)
         matrixHandle.values = list();
         for %__i__ = 1:size(h, "*")
             matrixHandle.values($+1) = extractSingleHandle(h(%__i__));
-            if or(fieldnames(matrixHandle.values($))=="user_data") then // TODO Remove after graphic branch merge
+            if or(fieldnames(matrixHandle.values($))=="user_data") then
                 if isList(matrixHandle.values($).user_data) then
                     matrixHandle.values($).user_data = inspectList(matrixHandle.values($).user_data)
                 elseif typeof(matrixHandle.values($).user_data) == "handle" then
@@ -150,32 +160,32 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedFigure = extractFigure(h)
         returnedFigure = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "figure_position", ...
-                "figure_size", ...
-                "axes_size", ...
-                "viewport", ...
-                "info_message", ...
-                "tag", ...
-                "auto_resize", ...
-                "figure_name", ...
-                "figure_id", ...
-                "color_map", ...
-                "pixmap", ...
-                "pixel_drawing_mode", ...
-                "anti_aliasing", ...
-                "immediate_drawing", ...
-                "background", ...
-                "rotation_style", ...
-                "event_handler", ...
-                "event_handler_enable", ...
-                "resizefcn", ...
-                "closerequestfcn", ...
-                "children", ...
-                "user_data"]);
-            
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "figure_position", ...
+        "figure_size", ...
+        "axes_size", ...
+        "viewport", ...
+        "info_message", ...
+        "tag", ...
+        "auto_resize", ...
+        "figure_name", ...
+        "figure_id", ...
+        "color_map", ...
+        "pixmap", ...
+        "pixel_drawing_mode", ...
+        "anti_aliasing", ...
+        "immediate_drawing", ...
+        "background", ...
+        "rotation_style", ...
+        "event_handler", ...
+        "event_handler_enable", ...
+        "resizefcn", ...
+        "closerequestfcn", ...
+        "children", ...
+        "user_data"]);
+
         fields = fieldnames(returnedFigure);
 
         for %__i__ = 1:size(fields, "*")
@@ -192,21 +202,21 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedLabel = extractLabel(h)
         returnedLabel = tlist([
-                    "ScilabSingleHandle", ...
-                    "type", ...
-                    "visible", ...
-                    "text", ...
-                    "font_foreground", ...
-                    "foreground", ...
-                    "background", ...
-                    "fill_mode", ...
-                    "font_style", ...
-                    "font_size", ...
-                    "fractional_font", ...
-                    "font_angle", ...
-                    "auto_rotation", ...
-                    "position", ...
-                    "auto_position"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "text", ...
+        "font_foreground", ...
+        "foreground", ...
+        "background", ...
+        "fill_mode", ...
+        "font_style", ...
+        "font_size", ...
+        "fractional_font", ...
+        "font_angle", ...
+        "auto_rotation", ...
+        "position", ...
+        "auto_position"]);
 
         fields = fieldnames(returnedLabel);
 
@@ -220,9 +230,9 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedTicks = extractTicks(ticks)
         returnedTicks = tlist([
-                    "Ticks", ...
-                    "locations", ...
-                    "labels"]);
+        "Ticks", ...
+        "locations", ...
+        "labels"]);
 
         fields = fieldnames(returnedTicks);
 
@@ -236,60 +246,60 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedAxes = extractAxes(h)
         returnedAxes = tlist([
-                    "ScilabSingleHandle", ...
-                    "type", ...
-                    "visible", ...
-                    "axes_visible", ...
-                    "axes_reverse", ...
-                    "grid", ...
-                    "grid_position", ...
-                    "x_location", ...
-                    "y_location", ...
-                    "view", ...
-                    "title", ...
-                    "x_label", ...
-                    "y_label", ...
-                    "z_label", ...
-                    "auto_ticks", ...
-                    "x_ticks", ...
-                    "y_ticks", ...
-                    "z_ticks", ...
-                    "box", ...
-                    "filled", ...
-                    "sub_tics", ...
-                    "font_style", ...
-                    "font_size", ...
-                    "font_color", ...
-                    "fractional_font", ...
-                    "isoview", ...
-                    "cube_scaling", ...
-                    "rotation_angles", ...
-                    "log_flags", ...
-                    "tight_limits", ...
-                    "data_bounds", ...
-                    "zoom_box", ...
-                    "margins", ...
-                    "axes_bounds", ...
-                    "auto_clear", ...
-                    "auto_scale", ...
-                    "hidden_axis_color", ...
-                    "arc_drawing_method", ...
-                    "hiddencolor", ...
-                    "line_mode", ...
-                    "line_style", ...
-                    "thickness", ...
-                    "mark_mode", ...
-                    "mark_style", ...
-                    "mark_size", ...
-                    "mark_size_unit", ...
-                    "mark_foreground", ...
-                    "mark_background", ...
-                    "foreground", ...
-                    "background", ...
-                    "clip_state", ...
-                    "clip_box", ...
-                    "children", ...
-                    "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "axes_visible", ...
+        "axes_reverse", ...
+        "grid", ...
+        "grid_position", ...
+        "x_location", ...
+        "y_location", ...
+        "view", ...
+        "title", ...
+        "x_label", ...
+        "y_label", ...
+        "z_label", ...
+        "auto_ticks", ...
+        "x_ticks", ...
+        "y_ticks", ...
+        "z_ticks", ...
+        "box", ...
+        "filled", ...
+        "sub_tics", ...
+        "font_style", ...
+        "font_size", ...
+        "font_color", ...
+        "fractional_font", ...
+        "isoview", ...
+        "cube_scaling", ...
+        "rotation_angles", ...
+        "log_flags", ...
+        "tight_limits", ...
+        "data_bounds", ...
+        "zoom_box", ...
+        "margins", ...
+        "axes_bounds", ...
+        "auto_clear", ...
+        "auto_scale", ...
+        "hidden_axis_color", ...
+        "arc_drawing_method", ...
+        "hiddencolor", ...
+        "line_mode", ...
+        "line_style", ...
+        "thickness", ...
+        "mark_mode", ...
+        "mark_style", ...
+        "mark_size", ...
+        "mark_size_unit", ...
+        "mark_foreground", ...
+        "mark_background", ...
+        "foreground", ...
+        "background", ...
+        "clip_state", ...
+        "clip_box", ...
+        "children", ...
+        "user_data"]);
 
         fields = fieldnames(returnedAxes);
 
@@ -311,34 +321,34 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedPolyline = extractPolyline(h)
         returnedPolyline = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "data", ...
-                "closed", ...
-                "line_mode", ...
-                "fill_mode", ...
-                "line_style", ...
-                "thickness", ...
-                "arrow_size_factor", ...
-                "polyline_style", ...
-                "interp_color_vector", ...
-                "interp_color_mode", ...
-                "mark_mode", ...
-                "mark_style", ...
-                "mark_size", ...
-                "mark_size_unit", ...
-                "foreground", ...
-                "background", ...
-                "mark_foreground", ...
-                "mark_background", ...
-                "x_shift", ...
-                "y_shift", ...
-                "z_shift", ...
-                "bar_width", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "data", ...
+        "closed", ...
+        "line_mode", ...
+        "fill_mode", ...
+        "line_style", ...
+        "thickness", ...
+        "arrow_size_factor", ...
+        "polyline_style", ...
+        "interp_color_vector", ...
+        "interp_color_mode", ...
+        "mark_mode", ...
+        "mark_style", ...
+        "mark_size", ...
+        "mark_size_unit", ...
+        "foreground", ...
+        "background", ...
+        "mark_foreground", ...
+        "mark_background", ...
+        "x_shift", ...
+        "y_shift", ...
+        "z_shift", ...
+        "bar_width", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedPolyline);
 
@@ -366,27 +376,27 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedSurface = extractSurface(h)
         returnedSurface = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "surface_mode", ...
-                "foreground", ...
-                "thickness", ...
-                "mark_mode", ...
-                "mark_style", ...
-                "mark_size", ...
-                "mark_size_unit", ...
-                "mark_foreground", ...
-                "mark_background", ...
-                "color_mode", ...
-                "color_flag", ...
-                "data", ...
-                "color_flag", ...
-                "hiddencolor", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data", ...
-                "cdata_mapping"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "surface_mode", ...
+        "foreground", ...
+        "thickness", ...
+        "mark_mode", ...
+        "mark_style", ...
+        "mark_size", ...
+        "mark_size_unit", ...
+        "mark_foreground", ...
+        "mark_background", ...
+        "color_mode", ...
+        "color_flag", ...
+        "data", ...
+        "color_flag", ...
+        "hiddencolor", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data", ...
+        "cdata_mapping"]);
 
         fields = fieldnames(returnedSurface);
 
@@ -406,11 +416,11 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedCompound = extractCompound(h)
         returnedCompound = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "children", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "children", ...
+        "user_data"]);
 
         fields = fieldnames(returnedCompound);
 
@@ -428,25 +438,25 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedRectangle = extractRectangle(h)
         returnedRectangle = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "thickness", ...
-                "mark_mode", ...
-                "mark_style", ...
-                "mark_size", ...
-                "mark_size_unit", ...
-                "mark_foreground", ...
-                "mark_background", ...
-                "line_mode", ...
-                "line_style", ...
-                "fill_mode", ...
-                "foreground", ...
-                "background", ...
-                "data", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "thickness", ...
+        "mark_mode", ...
+        "mark_style", ...
+        "mark_size", ...
+        "mark_size_unit", ...
+        "mark_foreground", ...
+        "mark_background", ...
+        "line_mode", ...
+        "line_style", ...
+        "fill_mode", ...
+        "foreground", ...
+        "background", ...
+        "data", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedRectangle);
 
@@ -460,20 +470,20 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedArc = extractArc(h)
         returnedArc = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "thickness", ...
-                "line_style", ...
-                "line_mode", ...
-                "fill_mode", ...
-                "foreground", ...
-                "background", ...
-                "data", ...
-                "arc_drawing_method", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "thickness", ...
+        "line_style", ...
+        "line_mode", ...
+        "fill_mode", ...
+        "foreground", ...
+        "background", ...
+        "data", ...
+        "arc_drawing_method", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedArc);
 
@@ -486,18 +496,18 @@ function [] = %_save(%__filename__, varargin)
     // CHAMP
     //
     function returnedChamp = extractChamp(h)
-         returnedChamp = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "data", ...
-                "line_style", ...
-                "thickness", ...
-                "colored", ...
-                "arrow_size", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        returnedChamp = tlist([
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "data", ...
+        "line_style", ...
+        "thickness", ...
+        "colored", ...
+        "arrow_size", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedChamp);
 
@@ -511,23 +521,23 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedSeg = extractSegs(h)
         returnedSeg = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "data", ...
-                "line_mode", ...
-                "line_style", ...
-                "thickness", ...
-                "segs_color", ...
-                "mark_mode", ...
-                "mark_style", ...
-                "mark_size", ...
-                "mark_size_unit", ...
-                "mark_foreground", ...
-                "mark_background", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "data", ...
+        "line_mode", ...
+        "line_style", ...
+        "thickness", ...
+        "segs_color", ...
+        "mark_mode", ...
+        "mark_style", ...
+        "mark_size", ...
+        "mark_size_unit", ...
+        "mark_foreground", ...
+        "mark_background", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedSeg);
 
@@ -541,14 +551,14 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedGrayplot = extractGrayplot(h)
         returnedGrayplot = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "data", ...
-                "data_mapping", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "data", ...
+        "data_mapping", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedGrayplot);
 
@@ -562,13 +572,13 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedMatplot = extractMatplot(h)
         returnedMatplot = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "data", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "data", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedMatplot);
 
@@ -582,19 +592,19 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedFec = extractFec(h)
         returnedFec = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "data", ...
-                "triangles", ...
-                "z_bounds", ...
-                "color_range", ...
-                "outside_colors", ...
-                "line_mode", ...
-                "foreground", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "data", ...
+        "triangles", ...
+        "z_bounds", ...
+        "color_range", ...
+        "outside_colors", ...
+        "line_mode", ...
+        "foreground", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedFec);
 
@@ -608,26 +618,26 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedLegend = extractLegend(h)
         returnedLegend = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "text", ...
-                "font_style", ...
-                "font_size", ...
-                "font_color", ...
-                "fractional_font", ...
-                "links", ...
-                "legend_location", ...
-                "position", ...
-                "line_mode", ...
-                "thickness", ...
-                "foreground", ...
-                "fill_mode", ...
-                "background", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data", ..
-                "paths"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "text", ...
+        "font_style", ...
+        "font_size", ...
+        "font_color", ...
+        "fractional_font", ...
+        "links", ...
+        "legend_location", ...
+        "position", ...
+        "line_mode", ...
+        "thickness", ...
+        "foreground", ...
+        "fill_mode", ...
+        "background", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data", ..
+        "paths"]);
 
         fields = fieldnames(returnedLegend);
 
@@ -636,7 +646,7 @@ function [] = %_save(%__filename__, varargin)
                 returnedLegend(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
             elseif fields(%__i__) == "paths" then
                 p = list();
-                for kl=1:size(h.links,'*');
+                for kl=1:size(h.links,"*");
                     p($+1) = get_entity_path(h.links(kl));
                 end
                 returnedLegend(fields(%__i__)) = p;
@@ -651,27 +661,27 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedText = extractText(h)
         returnedText = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "text", ...
-                "data", ...
-                "text_box", ...
-                "text_box_mode", ...
-                "foreground", ...
-                "font_style", ...
-                "font_size", ...
-                "font_angle", ...
-                "box", ...
-                "line_mode", ...
-                "fill_mode", ...
-                "font_foreground", ...
-                "background", ...
-                "alignment", ...
-                "fractional_font", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "text", ...
+        "data", ...
+        "text_box", ...
+        "text_box_mode", ...
+        "foreground", ...
+        "font_style", ...
+        "font_size", ...
+        "font_angle", ...
+        "box", ...
+        "line_mode", ...
+        "fill_mode", ...
+        "font_foreground", ...
+        "background", ...
+        "alignment", ...
+        "fractional_font", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedText);
 
@@ -685,23 +695,23 @@ function [] = %_save(%__filename__, varargin)
     //
     function returnedAxis = extractAxis(h)
         returnedAxis = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "visible", ...
-                "tics_direction", ...
-                "xtics_coord", ...
-                "ytics_coord", ...
-                "tics_color", ...
-                "tics_segment", ...
-                "tics_style", ...
-                "sub_tics", ...
-                "tics_labels", ...
-                "labels_font_size", ...
-                "labels_font_color", ...
-                "fractional_font", ...
-                "clip_state", ...
-                "clip_box", ...
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "visible", ...
+        "tics_direction", ...
+        "xtics_coord", ...
+        "ytics_coord", ...
+        "tics_color", ...
+        "tics_segment", ...
+        "tics_style", ...
+        "sub_tics", ...
+        "tics_labels", ...
+        "labels_font_size", ...
+        "labels_font_color", ...
+        "fractional_font", ...
+        "clip_state", ...
+        "clip_box", ...
+        "user_data"]);
 
         fields = fieldnames(returnedAxis);
 
@@ -715,18 +725,18 @@ function [] = %_save(%__filename__, varargin)
     //
     function returneduimenu = extractuimenu(h)
         returneduimenu = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "enable", ...
-                "foregroundcolor", ...
-                "label", ...
-                "visible", ...
-                "callback", ...
-                "callback_type", ...
-                "tag", ...
-                "checked", ...
-                "children", ..
-                "user_data"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "enable", ...
+        "foregroundcolor", ...
+        "label", ...
+        "visible", ...
+        "callback", ...
+        "callback_type", ...
+        "tag", ...
+        "checked", ...
+        "children", ..
+        "user_data"]);
 
         fields = fieldnames(returneduimenu);
 
@@ -744,9 +754,9 @@ function [] = %_save(%__filename__, varargin)
     //
     function returneduicontextmenu = extractuicontextmenu(h)
         returneduicontextmenu = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "children"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "children"]);
 
         fields = fieldnames(returneduicontextmenu);
 
@@ -764,35 +774,35 @@ function [] = %_save(%__filename__, varargin)
     //
     function returneduicontrol = extractuicontrol(h)
         returneduicontrol = tlist([
-                "ScilabSingleHandle", ...
-                "type", ...
-                "style", ...
-                "backgroundcolor", ...
-                "enable", ...
-                "fontangle", ...
-                "fontname", ...
-                "fontsize", ...
-                "fontunits", ...
-                "fontweight", ...
-                "foregroundcolor", ...
-                "horizontalalignment", ...
-                "listboxtop", ...
-                "max", ...
-                "min", ...
-                "position", ...
-                "relief", ...
-                "sliderstep", ...
-                "string", ...
-                "tooltipstring", ...
-                "units", ...
-                "value", ...
-                "verticalalignment", ...
-                "visible", ...
-                "callback", ...
-                "callback_type", ...
-                "user_data", ...
-                "tag", ...
-                "children"]);
+        "ScilabSingleHandle", ...
+        "type", ...
+        "style", ...
+        "backgroundcolor", ...
+        "enable", ...
+        "fontangle", ...
+        "fontname", ...
+        "fontsize", ...
+        "fontunits", ...
+        "fontweight", ...
+        "foregroundcolor", ...
+        "horizontalalignment", ...
+        "listboxtop", ...
+        "max", ...
+        "min", ...
+        "position", ...
+        "relief", ...
+        "sliderstep", ...
+        "string", ...
+        "tooltipstring", ...
+        "units", ...
+        "value", ...
+        "verticalalignment", ...
+        "visible", ...
+        "callback", ...
+        "callback_type", ...
+        "user_data", ...
+        "tag", ...
+        "children"]);
 
         fields = fieldnames(returneduicontrol);
 
@@ -807,24 +817,24 @@ function [] = %_save(%__filename__, varargin)
 
     // Utility function for legends, copy/paste from %h_load
     function p=get_entity_path(e)
-    // given a handle e on an entity this function returns its path relative
-    // to its parent axes.
-    // the path is a vector of child index.
-    p=[];
-    parent=e.parent;
-
-    while  %t
-        pos=find(parent.children==e,1)
-        if pos==[] then
-            error(msprintf(_("%s : Invalid entity %s\n"),"save","Legend"))
-        end
-        p=[pos p]
-        if parent.type=='Axes' then
-            break
-        end
-        e=parent
+        // given a handle e on an entity this function returns its path relative
+        // to its parent axes.
+        // the path is a vector of child index.
+        p=[];
         parent=e.parent;
-    end
+
+        while  %t
+            pos=find(parent.children==e,1)
+            if pos==[] then
+                error(msprintf(_("%s : Invalid entity %s\n"),"save","Legend"))
+            end
+            p=[pos p]
+            if parent.type=="Axes" then
+                break
+            end
+            e=parent
+            parent=e.parent;
+        end
     endfunction
 
     function macro = extractMacro(macroPtr, macroName)
@@ -840,41 +850,41 @@ function [] = %_save(%__filename__, varargin)
     //save environment
     if size(varargin) == 0 then
         %__excludeList__ = [
-            "%_save"
-            "isList"
-            "isMacro"
-            "isCompiledMacro"
-            "inspectList"
-            "extractMatrixHandle"
-            "extractSingleHandle"
-            "extractFigure"
-            "extractLabel"
-            "extractTicks"
-            "extractAxes"
-            "extractPolyline"
-            "extractPlot3d"
-            "extractFac3d"
-            "extractSurface"
-            "extractCompound"
-            "extractRectangle"
-            "extractArc"
-            "extractChamp"
-            "extractSegs"
-            "extractGrayplot"
-            "extractMatplot"
-            "extractFec"
-            "extractLegend"
-            "extractText"
-            "extractAxis"
-            "extractuimenu"
-            "extractuicontextmenu"
-            "extractuicontrol"
-            "get_entity_path"
-            "extractMacro"
-            "%__excludeList__"
-            "%__filename__"
-            "varargin"
-            "%__varList__"];
+        "%_save"
+        "isList"
+        "isMacro"
+        "isCompiledMacro"
+        "inspectList"
+        "extractMatrixHandle"
+        "extractSingleHandle"
+        "extractFigure"
+        "extractLabel"
+        "extractTicks"
+        "extractAxes"
+        "extractPolyline"
+        "extractPlot3d"
+        "extractFac3d"
+        "extractSurface"
+        "extractCompound"
+        "extractRectangle"
+        "extractArc"
+        "extractChamp"
+        "extractSegs"
+        "extractGrayplot"
+        "extractMatplot"
+        "extractFec"
+        "extractLegend"
+        "extractText"
+        "extractAxis"
+        "extractuimenu"
+        "extractuicontextmenu"
+        "extractuicontrol"
+        "get_entity_path"
+        "extractMacro"
+        "%__excludeList__"
+        "%__filename__"
+        "varargin"
+        "%__varList__"];
 
         //get all user variables
         %__varList__ = who_user(%f);
@@ -904,17 +914,23 @@ function [] = %_save(%__filename__, varargin)
         if isList(temp) then
             //list container
             value = inspectList(temp);
-            //update 
+            //update
             execstr(varargin(%__i__) + " = value");
         elseif typeof(temp) == "handle" then
-            //convert handle to tlist
-            value = extractMatrixHandle(temp);
-            //update 
-            execstr(varargin(%__i__) + " = value");
+            if ~is_handle_valid(temp) then // Invalid handle ignored
+                warning(oldMode);
+                warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save"));
+                warning("off");
+                varargin(%__i__) = null();
+            else //convert handle to tlist
+                value = extractMatrixHandle(temp);
+                //update
+                execstr(varargin(%__i__) + " = value");
+            end
         elseif isMacro(temp) | isCompiledMacro(temp) then
             //convert macro to tlist
             value = extractMacro(temp, varargin(%__i__));
-            //update 
+            //update
             execstr(varargin(%__i__) + " = value");
         elseif type(temp) == 14 then //library, must not be save
             varargin(%__i__) = null();