Code runs when stepping in debugger, but when run normally I lose fields from handles structure
Show older comments
Edit:Made code variable names more clear
Using Matlab 2016a, on a 3gig ram machine
I'm developing a simple media player within a GUI using a timer and a few control buttons. The code was running videos as desired, so i set about adding my start/stop/pause buttons. These are simple and work as intended (when no video running) however since adding them i can no longer run videos properly.
The GUI stores data about the current frame and what direction playback is in in my handles structure, on each call of the timer I update the handles structure.
The problem i'm experiencing is that after one or two calls of the timer function I lose certain data fields within my handle structure stopping the player from working. I can't work out why this is happening, I call no other functions between the timer function calls, and the same code was previously working. When i came to debug this I found that there were no errors and in fact when stepping through the debugger the code actually works fine and there is no data loss.
The timer function is as follows:
{
function timerfunc(~,~,GUI_Figure_Handle)
handles = guidata(GUI_Figure_Handle);
handles.current_frame = handles.current_frame+handles.current_command;
if handles.current_frame ~= handles.no_frames
imshow(handles.movie_data(handles.currrent_frame).cdata,'parent',handles.player;
handles.text2.String = handles.current_frame*0.02;
drawnow;
end
guidata(GUI_Figure_Handle,handles);
}
As I say the only thing I believe I've changed is adding some other functions none of which are called. I'm not losing all the fields of handles structure either, only a few that I'm setting after initializing the GUI. But not all of the lost variables are accessed by the timer.
Due to the code running when its operated step by step I'm unsure that my code is directly to blame and wonder if it could be to do with memory.
Any help would be much appreciated.
2 Comments
Adam
on 23 Mar 2017
What is 'handles' that is being passed in to your function? This is a very odd name for what it appears to be. It clearly isn't the handles struct as you pass it to guidata and assign the result to something you call 'handle' so I am assuming 'handles' is the handle to your main GUI?
Tom Pryke
on 23 Mar 2017
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!