"Attempt to modify the tree during an update traversal"

26 vues (au cours des 30 derniers jours)
Roman Müller-Hainbach
Roman Müller-Hainbach le 26 Fév 2015
Commenté : song yuxuan le 24 Sep 2020
I encountered an error while using Matlab that seemingly no one else encountered before me. Or atleast no one on the forum or elsewhere reported it. Someone may need to help me on what code to post here but what I'm really into is what this error message even means.
I have a figure with tabs in it an subplots within that. I created a data cursor object and defined my own UpdateFcn. Via the event_obj and all the Parent/Children-connections I am able to get handles to Line objects in different axes. What I want to do is change the color of both the line that was clicked on and a corresponding line in another subplot. However, most the time (not always) I get the error you see in the title when I try to assign new values to those Line object's properties (e.g Color or LineWidth).
It looks like manipulating the Line in the other axes environment (the other subplot) is the more toxic, but it happens anyway.
I am really running out of ideas on how to figure out what is going on here. All the handles are valid and I don't even know what this message is talking about.
Any ideas?
  6 commentaires
song yuxuan
song yuxuan le 24 Sep 2020
Same here, in Matlab 2020a
song yuxuan
song yuxuan le 24 Sep 2020
Error using matlab.graphics.chart.primitive.Scatter/doUpdate
Data lengths must match.
Error using matlab.graphics.axis.Axes/GetLayoutInformation
Attempt to modify the tree during an update traversal.
Error in matlab.graphics.interaction.internal.isAxesHit
Error in matlab.graphics.interaction.internal.hitAxes
Error in matlab.graphics.interaction.uiaxes.DefaultAxesInteractionStrategy/isObjectHit
Error in matlab.graphics.interaction.uiaxes.DataTipsBase/validate
Error in matlab.graphics.interaction.uiaxes.DataTipsBase/lingerEnterCallback
Error in matlab.graphics.interaction.uiaxes.DataTipsBase>@(o,e)hObj.lingerEnterCallback(o,e)
Error in matlab.graphics.interaction.actions.Linger/enterEvent
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Error using matlab.graphics.axis.dataspace.CartesianDataSpace/updateTransforms
Attempt to modify the tree during an update traversal.
Error in matlab.graphics.internal.getSpatialTransforms (line 68)
updateTransforms(hDataSpace);
Error in matlab.graphics.chart.interaction.dataannotatable.picking.AnnotatablePicker/isValidInPickSpace (line 14)
[~, ~, ds, matBelow] = matlab.graphics.internal.getSpatialTransforms(hContext);
Error in matlab.graphics.chart.interaction.dataannotatable.picking.AnnotatablePicker/nearestFacePoint (line 35)
valid = obj.isValidInPickSpace(hContext, varargin{:});
Error in matlab.graphics.chart.interaction.dataannotatable.SurfaceHelper>localGetNearestVertex (line 214)
[index, faceIndex, intFactors] = pickUtils.nearestFacePoint(hSurface, position, isPixelPoint, f, verts);
Error in matlab.graphics.chart.interaction.dataannotatable.SurfaceHelper.getNearestPoint (line 43)
index = localGetNearestVertex(hObj, position, true);

Connectez-vous pour commenter.

Réponses (2)

Mike Garrity
Mike Garrity le 17 Nov 2015
That's some new error checking that was added in R2014b.
It's detecting a case where code that's running during a drawnow is making a change which isn't going to be flushed to the screen during the drawnow. In earlier versions, this resulted in cases where it quietly drew incorrect results. We really wanted to hunt all of those cases down before R2014b shipped. It sounds like you've found one we missed. Do you have some repro steps we could use? If so, could you send them into MathWorks support?
Thanks!

Massimo Ciacci
Massimo Ciacci le 24 Sep 2019
Modifié(e) : Massimo Ciacci le 24 Sep 2019
The best workaround seems to avoid changing the properties of the data tip within the text update function.
First create a data tip, then change its properties, and only when all is ready call the DataCursorManager text update. This function is an example:
% M.Ciacci, 24/09/2019
function add_one_Data_Tip( sel_x_val , h_curve, fontSize)
% inputs:
% h_curve = a single Line handle
% sel_x_val = x value where data tip is requested
%example
% figure(); p_h = plot(0:10,(0:10).^2,'b'); add_one_Data_Tip( 4.5 , p_h, 16)
% retrieve the datacursor manager
cursorMode = datacursormode(gcf);
set(cursorMode, 'UpdateFcn',@customDatatipFunction);
% create a tip somewhere
h_Dtip = cursorMode.createDatatip(h_curve) ;
% set tip properties
markerColor = get(h_curve,'color'); %same color as curve
markerEColor = 'k';
set(h_Dtip, 'MarkerSize',5,'MarkerFaceColor',markerColor,...
'MarkerEdgeColor',markerEColor, 'Marker','o'); %'HitTest','off'
%% ==> set tip in the right x,y location
xdata = get(h_curve,'XData') ;
ydata = get(h_curve,'YData') ;
[~,idx] = min(abs(xdata - sel_x_val));
% use interpolation
h_Dtip.Interpolate ='on';
if idx < length(xdata)
if idx > 1
xx=xdata([idx-1,idx,idx+1]);
yy=ydata([idx-1,idx,idx+1]);
else
xx=xdata([idx,idx+1]);
yy=ydata([idx,idx+1]);
end
else
xx=xdata([idx-1,idx]);
yy=ydata([idx-1,idx]);
end
yItp=interp1(xx,yy,sel_x_val);
% set tip location
pos = [sel_x_val , yItp ,0];
set(h_Dtip, 'Position', pos,'BackgroundColor',[238 235 141]/255);
% invoke text update function and more: ### no changing allowed in there !! ###
updateDataCursors(cursorMode)
%% set other properties
set(h_Dtip,'FontSize',fontSize,'FontName','Comic Sans MS');
% no tip properties changing allowed in here, would risk to crash as well
function output_txt = customDatatipFunction(~,evt)
pos = get(evt,'Position');
output_txt = {
['X = ',sprintf('%6.2g',pos(1))] ;
['Y = ',sprintf('%7.3g',pos(2))] };
% check if there is a Z-coordinate, if so display that too
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),3)];
end
% e.g. this would cause the error
%% "Attempt to modify the tree during an update traversal"
%% and even crash Matlab at times
% alldatacursors = findall(gcf,'type','hggroup');
% set(alldatacursors,'FontSize',12);

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by