I have a GUI for an image stack and the main axis has patches on it. These handles to these are stored in an array: myData.mainGUIWindowGraphicsHandles() In some situations, the user clicks on one of these patches and a new figure window pops up which allows the user to look at that region of the image stack in more detail. This figure has its own axis and it also has its own patch objects. Furthermore, the function that draws the second figure also puts some rectangles on the main Gui Window. These extra rectangles have as a parent the mainGUIWindow axis, but the handles are stored in the guidata object for the 2nd window.
So the situation is: 2 figures, an axis on each, one triggered by a mouse click on the other. Patches on both.
The 2nd figure is actually made at the start of the entire GUI but it is just set to Visibility=off and HitTest=off. When it is triggered, I set these to on. However, each time I use it I want to reset the graphics - removing the previous graphics completely.
I have the command: cla(SecondFigureAxis,'reset')
When I do this, it does exactly what it is supposed to do for the second figure, but it also, somehow, changes the array of patch handles for the main GUI window too. Suddenly, many of them are no longer valid handles which messes up downstream GUI functions. (before, a call to ishandle for the handles array gives all 1s. After, there are strings of 0s).
I have traced the problem to the cla() line, but can't figure out why it would do this and how to fix it. I'd be happy to share the code and dependencies, an input file, and instructions on how to get the error if someone could help me.