graphic handle save/load bug

1 次查看(过去 30 天)
Kyle Watson
Kyle Watson 2021-3-9
The following class followed by the subsequent commands produces the final error/warning. The problem is summarized below and all the steps must happen for the bug to occur.
  1. create a class that adds a dynamic property to a graphic
  2. The graphic is stored as an object property
  3. the graphic has a valueChangedFunction that references a method of the object
  4. We save specifically as v7.3
  5. We load and then add the dynamic property back to the graphic. This is required to maintain the set/get methods of said dynamic property. Another way to do it would be to make the "nonCopyable" property false so it properly copies over and saves. However we dont' really want this as if the code changes in the future for how to reference the dynamic property I'd prefer for the new functionality to be implemented instead of the old.
  6. We have a property that has a function_handle property type that is empty
  7. Upon load, the old function_handle is attempted to be set, but it's not set as a 0x0 function_handle but instead as [] which then fails the function_handle type requirement.
Again if any of these exact requirements are not met everything works. For example if the function_handle isn't empty it is properly stored and retrieved. Also any other empty type seems to copy and be preserved properly. I plan on making a change here to simply not store an empty function_handle but instead use a nop function_handle which just does nothing. However I'm a little concerned as to what other incorrect property saving/loading could be happening in the v7.3 save/load.
classdef Test
properties
graphic
func function_handle
end
methods (Static)
function out = loadobj(in)
out = in;
out.addDyn;
end
end
% constructor
methods (Access = public)
function this = Test()
% construct graphic
uiParent = uifigure;
drawnow
this.graphic = uieditfield(uiParent);
% assign some callback from this object to the graphic
this.graphic.ValueChangedFcn = @(varargin)exampleValueChangedCallback(this);
% also assign some dynamic field to the graphic which also
% references this object
this.addDyn;
end
function addDyn(this)
h = findprop(this.graphic, 'func');
if isempty(h)
h = addprop(this.graphic, 'func');
end
h.SetMethod = @(uicontrol, value)testHelper(this, 'func', value);
h.GetMethod = @(varargin)this.func;
%h.NonCopyable = false;
end
function testHelper(this, prop, val)
this.(prop) = val;
end
function exampleValueChangedCallback(this)
end
end
end
And then run this code:
h = Test();
save tmp.mat h -v7.3
load tmp.mat
We get this error/warning
Warning: While loading an object of class 'EditField':
Error setting property 'func' of class 'Test':
Invalid data type. Value must be function_handle or be convertible to function_handle.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by