changeset 18317:0187ed948627

Fix segfault with copyobj() and patch objects. * copyobj.m: Uncomment failing demo block. * struct2hdl.m (create_patch): When creating a patch using face/vertices syntax, don't restore xdata, ydata, zdata, or cdata since these are derived values.
author Rik <rik@octave.org>
date Mon, 20 Jan 2014 21:45:53 -0800
parents ff311e5ff6d8
children 21e14380c3ad
files scripts/plot/util/copyobj.m scripts/plot/util/struct2hdl.m
diffstat 2 files changed, 24 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/copyobj.m	Mon Jan 20 22:16:22 2014 -0500
+++ b/scripts/plot/util/copyobj.m	Mon Jan 20 21:45:53 2014 -0800
@@ -86,32 +86,25 @@
 %! legend ('errorbar', 'line');
 %! hnew = copyobj (hdl);
 
-%!#demo
-%! ## FIXME: This demo fails for an obscure reason.
-%! ## It appears that there is something wrong with Octave code for patches.
-%! ## This demo must remain commented out until patch() has been reworked.
-%! unwind_protect
-%!   hdl = figure (1234);
-%!   clf;
-%!   subplot (2,2,1);
-%!   hold on;
-%!   contourf (rand (10, 10));
-%!   colorbar ();
-%!   subplot (2,2,2);
-%!   quiver (rand (10, 10), rand (10, 10));
-%!   subplot (2,2,3);
-%!   colormap (jet (64));
-%!   hold on;
-%!   sombrero ();
-%!   colorbar ('peer', gca, 'NorthOutside');
-%!   subplot (2,2,4);
-%!   imagesc (rand (30, 30));
-%!   text (15, 15, 'Rotated text', ...
-%!         'HorizontAlalignment', 'Center', 'Rotation', 30);
-%!   hnew = copyobj (hdl);
-%! unwind_protect_cleanup
-%!   close all;
-%! end_unwind_protect
+%!demo
+%! hdl = figure (1234);
+%! clf;
+%! subplot (2,2,1);
+%! hold on;
+%! contourf (rand (10, 10));
+%! colorbar ();
+%! subplot (2,2,2);
+%! quiver (rand (10, 10), rand (10, 10));
+%! subplot (2,2,3);
+%! colormap (jet (64));
+%! hold on;
+%! sombrero ();
+%! colorbar ('peer', gca, 'NorthOutside');
+%! subplot (2,2,4);
+%! imagesc (rand (30, 30));
+%! text (15, 15, 'Rotated text', ...
+%!       'HorizontAlalignment', 'Center', 'Rotation', 30);
+%! hnew = copyobj (hdl);
 
 %!testif HAVE_MAGICK
 %! toolkit = graphics_toolkit ();
--- a/scripts/plot/util/struct2hdl.m	Mon Jan 20 22:16:22 2014 -0500
+++ b/scripts/plot/util/struct2hdl.m	Mon Jan 20 21:45:53 2014 -0800
@@ -297,7 +297,11 @@
   h = patch (prp);
   set (h, "parent", par);
   s.properties = rmfield (s.properties,
-                            {"faces", "vertices", "facevertexcdata"});
+                          {"faces", "vertices", "facevertexcdata"});
+  ## Also remove derived properties.  Otherwise there is a possibility for
+  ## a segfault when 'set (h, properties)' is used to restore properties
+  ## which do not match in size the ones created with from the call to patch().
+  s.properties = rmfield (s.properties, {"xdata", "ydata", "zdata", "cdata"});
   addmissingprops (h, s.properties);
   sout = s;
 endfunction