WindowButtonMotionFcn producing strange errors

8 views (last 30 days)
Hi, I have a program which has a WindowButtonMotionFcn executed within a loop to detect mouse movement. The loop plots stuff with axes and labels parameters as long as x=1 (while x=1...). I have another callback which stops the loop when I click on the background by setting x=0. Everything works fine but I still get those error codes at the end:
Error using handle.handle/get Invalid or deleted object.
Error using drawnow Error while evaluating figure WindowButtonMotionFcn
Error using handle.handle/get Invalid or deleted object.
Error using figure Error while evaluating figure WindowButtonMotionFcn
Error using handle.handle/get Invalid or deleted object.
Error using figure Error while evaluating figure WindowButtonMotionFcn
I have no idea where it is coming from and I would like to get rid of it.
Thank you!
  4 Comments
Antoine
Antoine on 5 Jun 2014
I managed to solve my problem by closing the figure window. Thank you for your help!
Geoff Hayes
Geoff Hayes on 5 Jun 2014
That's an interesting way to have done the callback for your button - I wouldn't have thought to do it like that. Is y a global variable then? An alternative would have been to do something like
buttonno=uicontrol('style','pushbutton','string','NO',...
'fontsize',16,'units','normalized',...
'position',[0.120 0.875 0.06,0.08],...
'callback',@noButtonCallback);
Then have the callback defined as
function noButtonCallback(hObject,eventData)
set(figureHandle,'WindowButtonMotionFcn',...
'mil=get(ax(2),''CurrentPoint'');')
end
With another callback in place of the 'mil=get(ax(2))' function. I guess that mil is another global variable? As is ax and figureHandle?
(Event my callback won't work without declaring the global variable of figureHandle.)
Since the * WindowButtonMotionFcn* is just mil=get(ax(2),''CurrentPoint''), then the ax may become undefined/invalid/empty when the loop stops.
It is kind of challenging to debug this sort of problem since you can't really step through the callbacks to see how they are being evaluated.
I urge you to consider using actual functions as your callbacks (similar to noButtonCallback above) so that when you encounter a problem, you can put in a breakpoint at the function that is failing and step through its code to see what is going wrong.

Sign in to comment.

Answers (0)

Categories

Find more on Environment and Settings 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!