MATLAB Answers

Matt J

Continuously pressing GUI slider arrow causes hanging

Asked by Matt J
on 4 Oct 2012

I've created a GUI with slider controls. When I make distinct individual clicks of the slider arrows, it works fine. When I hold the arrow buttons down continuously, however, the slider GUI freezes. I can continue to move the slider, but it has no effect on the rest of the GUI.

What appears to be happening is that by holding down the arrow, the slider callback gets launched many times repeatedly and faster than MATLAB can refresh the GUI graphics with the effect of the slider change. Ultimately, it chokes and cannot catch up.

Is there some way that the continuous-arrow-press condition is supposed to be processed? I notice that sliders have a ButtonDownFcn property, but I don't know what role it's supposed to play.

Or might there be some way to force the GUI to wait until all other graphics and uicontrol data in the figure are refreshed before re-executing the callback?


Log in to comment.


1 Answer

Answer by Sean de Wolski
on 4 Oct 2012
 Accepted Answer

The ButtonDownFcn is disabled if the uicontrol is enabled. What is the BusyAction of the slider? If it is cancel that is self explanatory. Else I would suggest adding a drawnow in the callback to force a flush of the event queue.


Show 1 older comment

Kind of contrary, yes. I would expect the 'cancel' to not queue the new events but also to not fire whatever new events those were supposed to be. Is there evidence that they're firing even with the smooth transition?

The changes in the slider are now successfully inducing all the other effects in the gui window that they're intended to.

I don't know what other events could previously have been trying to interrupt the slider callback. There's nothing else running except the slider callback.

Thanks. I think I understand now why BusyAction='cancel' is helping. Slider callback events are continuously/repeatedly fired while the arrow button is being held down. However, the only ones that are deleted from the queue are those that are attempting to interrupt the currently executing version of the callback (because the slider is also Interruptible='off'). The event scheduler resumes processing further triggerings of the callback once the current one has finished. This is enough to create the illusion of continuous sliding.

Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today