- https://www.mathworks.com/help/matlab/ref/handle.isvalid.html
- https://www.mathworks.com/help/matlab/ref/getappdata.html
GetAppData Error when trying to close an installed MATLAB app that I have built and packaged
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi!
I am having problems when attempting to close an INSTALLED MATLAB App, that I built and packaged myself.
The app closes correctly with no errors when run normally in MATLAB and as a standalone app using runtime. However, after successfully installing and running the app from 'MATLAB Apps', when you attempt to close the app, it throws out the following error:
Error using getappdata
Value must be a handle.
Error in BeamDeflectionLabApp/attachOncleanupToFigure (line 109)
appdata = getappdata(fig);
Error in BeamDeflectionLabApp/startApp (line 94)
obj.attachOncleanupToFigure(appdesigner.internal.service.AppManagementService.getFigure(obj.AppHandle));
Error in BeamDeflectionLabApp (line 48)
startApp(obj)
Error in appinstall.internal.runapp>execute (line 116)
out = evalin('caller', [script ';']);
Error in appinstall.internal.runapp>runapp13a (line 95)
outobj = execute(fullfile(appinstalldir, [wrapperfile 'App.m']));
Error in appinstall.internal.runapp>preamble18b (line 60)
appobj = runapp13a(appinstalldir);
Error in appinstall.internal.runapp (line 13)
out = preamble18b(appinstalldir);
Error in matlab.apputil.run (line 45)
appinstall.internal.runapp(appName, appLocation);
I have tried everything under the sun to try and stop this from happening and I can only assume it is attempting to do something after the app has already been deleted.
I did find this Question: https://uk.mathworks.com/matlabcentral/answers/451421-packaged-app-error-r2018b that included the same errors, but there wasn't really a solution provided. Is there anything I can add into my code to correct this or an easy fix? I can share the app code if that makes diagnosis easier?
Thanks!
0 comentarios
Respuestas (1)
sanidhyak
el 11 de Mayo de 2025
I understand that you are encountering an error while closing a packaged MATLAB App. The mentioned error typically arises because the app is trying to access the app’s main figure handle (“fig”) after it has already been deleted. This happens during the cleanup phase or in delayed callbacks.
The root cause here is that the “getappdata(fig)” function is called without confirming if “fig” is still a valid handle, which causes the function to throw an error once the app has been closed or disposed of.
To resolve this, you can simply wrap the “getappdata” function call in a validity check using MATLAB’s “isvalid” function. Please refer to the corrected version of the function below:
function attachOncleanupToFigure(obj, fig)
if isvalid(fig)
appdata = getappdata(fig);
% (continue with logic as needed)
else
return; % Avoid further execution if figure is no longer valid
end
end
This now ensures that all post-closure or cleanup routines do not unintentionally access deleted components.
For further reference, kindly refer to following official documentation:
I hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!