Gui appears and disappears before user can do anything with it

10 visualizaciones (últimos 30 días)
I have been working on a script and gui for sometime and have now decided to completely restructure my code. I have blocked out large chunks of it until I can move it to its new home. As far as I can tell, the only code left operational in the gui is that which is automatically generated by GUIDE. The exception to this is the code in the uicontrol callbacks, but that should only run once invoked by the user, and a setappdata line in OpeningFcn.
The problem is my gui just appears and immediately disappears. On debugging, I've found that it doesn't even get to OpeningFcn, so must have a problem somewhere before that. Further debugging shows that the gui appears and disappears when the following line from gui_mainfcn.m is run:
gui_hFigure = matlab.hg.internal.openfigLegacy(name, singleton, visible);
This is at line 286 and is the 'else' statement in the function local_openfig.
In addition, weird other events also happen - like I can't close Matlab without it going into debug mode and then getting stuck in a loop. I can only get out if I press the window close cross many times.
I'm afraid this is completely beyond my level of Matlab so I'd be grateful for any help on why this has started happening.
UPDATE: If I comment out the following line from OpeningFcn then it behaves properly:
setappdata(gcbf,'BreakLoop',true);
I'm struggling to understand this if it doesn't even get to OpeningFcn. What's wrong with this line of code?
Regards.
  6 comentarios
Stephen23
Stephen23 el 24 de Oct. de 2018
"..where is setappdata data actually stored?"
Within the graphics object itself (i.e. the figure).
"Is it visible to me anywhere or can it only be accessed using getappdata?"
You might be able to access it using set get, but I would not recommend doing this: the appdata functions neatly encapsulate the field generation and make the storing and retrieval robust.
"Having used setappdata I notice that nothing appears in the workspace."
There are many workspaces, not just the base workspace. Each workspace is independent, and requires variables to be explicitly passed between them (and that is how it should be). You can view other workspaces by using the debugging tools.
Walter Roberson
Walter Roberson el 24 de Oct. de 2018
OpeningFcn is an invention of GUIDE, not a true callback. I don't know what gcbf would refer to during OpeningFcn.

Iniciar sesión para comentar.

Respuesta aceptada

Rik
Rik el 24 de Oct. de 2018
It is not because the figure is not visible yet, but because the GUI figure is not a callback figure at that point (at the most it will be the current figure, see gcf). Using an explicit handle to your figure in that line of code would be best.

Más respuestas (0)

Categorías

Más información sobre Maintain or Transition figure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by