MATLAB Answers

"Attempt to modify the tree during an update traversal"

20 views (last 30 days)
Roman Müller-Hainbach
Roman Müller-Hainbach on 26 Feb 2015
Edited: Massimo Ciacci on 24 Sep 2019
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?

  4 Comments

Show 1 older comment
Grg
Grg on 16 Nov 2015
Same here, using r2015a as well. Any ideas?
Charles McPherson
Charles McPherson on 10 Feb 2016
Is there a fix for this yet, or at least a workaround?

Sign in to comment.

Answers (2)

Mike Garrity
Mike Garrity on 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!

  0 Comments

Sign in to comment.


Massimo Ciacci
Massimo Ciacci on 24 Sep 2019
Edited: Massimo Ciacci on 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);

  0 Comments

Sign in to comment.

Sign in to answer this question.