altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.27k stars 365 forks source link

Export enters an endless loop when called from within a live editor file #375

Closed bernb closed 1 year ago

bernb commented 1 year ago

For example,

[x,y] = meshgrid(1:15,1:15);
z = peaks(15);
T = delaunay(x,y);
p = trisurf(T,x,y,z);
export_fig(p.Parent, "test.png");

does work as intended when used from within the command window or a regular matlab file, but it seems to enter an endless loop when used from within the live editor (a *.mlx file). The issue seems to be related to drawnow.

A possible workaround is to undock the figure before exporting. This does however prevent it from being shown in the output column of the live editor:

[x,y] = meshgrid(1:15,1:15);
z = peaks(15);
T = delaunay(x,y);
p = trisurf(T,x,y,z);
set(p.Parent.Parent, 'Visible', 'on');
export_fig(p.Parent, "test.png");
set(p.Parent.Parent, 'Visible', 'off');

Matlab version: 2022b

altmany commented 1 year ago

Thanks for the report. I fixed the endless recursion in the latest commit (c2126db)