Hi Hilton,
I understand that the 'onMouseMove’ callback function of your GUI program is throwing an error. The error is related to ‘text’ object because it is being deleted by some other process before its properties can be set. Please follow the given recommendations to debug your code:
- Check if the `PillarsStatsPanel` or its children are being modified or deleted elsewhere in your code. It is possible that another part of your program is modifying the GUI elements while the `onMouseMove` function is still running.
- Verify that the `m_hnd` array is correctly initialized and updated. Make sure that the number of elements in `m_hnd` matches the number of children in `PillarsStatsPanel`. If the number of children changes dynamically, you may need to update `m_hnd` accordingly.
- Check if the `app.PillarsStatsPanel.Children.Children(i)` object is valid and not deleted before calling the `text` function. You can add a check to ensure that the object is not empty or deleted. Here is an example code using ‘try-catch’ block and ‘isvalid’ function to ensure that `app.PillarsStatsPanel.Children.Children(i)` is a valid object before attempting to create the text object.
function onMouseMove(this, ~, ~)
if ~isempty(this.m_hnd)
delete(this.m_hnd);
this.m_hnd = gobjects(0);
end
for i = 1:numel(app.PillarsStatsPanel.Children.Children)
childObj = app.PillarsStatsPanel.Children.Children(i);
if ~isempty(childObj) && isvalid(childObj)
this.m_hnd(i) = hggroup(childObj);
try
h1 = text(childObj, this.GetX(), this.GetY(), this.GetText(), 'Parent', this.m_hnd(i));
% Additional code for customizing the text object if needed
% ...
catch err
%add a warning message
end
end
end
end
The above recommendations should help to troubleshoot your issues.
For more information on ‘try-catch’ block and ‘MATLAB code analysis’ for debugging, please follow the MATLAB documentation links given below:
- https://www.mathworks.com/help/matlab/ref/try.html
- https://www.mathworks.com/help/coder/matlab-code-analysis.html
I hope this helps!
Thank you,
Abhimenyu.