Very slow graphics when mouse pointer moves around a figure

I've got a little widget that animates a sequence of images by calling the "image()" function repeatedly with new images in a sequence. Normally the animation proceeds reasonably fast around 50-60 frames per second. However, if the mouse is in the figure window and moves around (not even clicking on anything), then the animation slows to a crawl (about 2-3 frames per second) as long as the mouse moves in the figure window. (See code at bottom for simple example to replicate this).
I've checked to ensure that the 'WindowButtonMotionFcn' figure callback is disabled (as are all other figure callbacks). I can't find any other figure, axes or even image objects that might be triggered by mouse motion in the figure window.
If I run the profiler and compare results with and without the mouse moving around the figure window, I see the function:
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
(and its dependent functions ) is getting called thousands of times and is consuming 90% of the runtime when the mouse is moving around I tried turning off both the figure's toolbar and the figure's menu bar, e.g:
hFigure.ToolBar = 'none';
hFigure.MenuBar = 'none';
and that slightly alleviates the issue somewhat, but not much (perhaps 10-20% better) . Further, even with the toolbars turned off, the profiler still indicates that
ToolbarController.ToolbarController>@obj.handleMouseMotion
is still consuming 90% of the run time whenever the mouse is moving around. There also is the function
AxesToolbarButton.AxesToolbarButton>AxesToolbarButton.AxesToolbarButton
that is also getting called thousands of times and is consuming some of the time. So I also disable the AxesToolbar by:
axesTB = get(hAxes,'ToolBar');
axesTB.visible = 'off';
axesTB.BusyAction = 'cancel';
(Unlike the figure toolbar, there doesn't seem a setting to completely disable a AxesToolbar). Anyway, turning off the axesTB didn't seem to help.
% This code can be used to illustrate the issue of slowly updating graphics.
% Run this, and then move the mouse around the figure window.
for loop=1:500
image(rand(300,300),'CDataMapping','scaled');
drawnow;
end
%Clearing the axes with "cla" before the image() call doesn't change the result. However, this version of the code is seemingly NOT impacted by this issue or very little:
hImg = image(rand(300,300),'CDataMapping','scaled');
for loop=1:500
hImg.CData = rand(300,300);
drawnow;
end
In the latter case, the profiler say that the function
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
still gets called a whole bunch of times but it ends up only consuming about 15% of the runtime (not 90+%), and the animation proceeds at 50+ FPS. So there is something about the combination of a moving mouse and creating new objects (rather than changing attributes of existing objects) that seems to grind matlab graphics to a halt. While I clearly point out a workaround for my little example above, in the general case, such workarounds are not always possible. It seems odd that moving a mouse while drawing objects in a figure shouldn't necessarily slow down things as much as it appears to do.
Thoughts appreciated.

9 commentaires

I don't have the solution, but I want to add that I have the same problem in a GUI. Much better performance for older MATLAB versions. This problem has been there for years now, why not make it possible to disable any toolbarcontroller for GUI applications?
I have the same Issue.
it takes for ever and i have a dedicated graphics card and 20GB ram
Also can't help, but just want to add that I've had problems with this too. I have a GUI that displays live feeds from two USB cameras. The framte rate drops and it crashes regulalrly whenever the mouse is moved, making it unusable.
Would be great if someone found a solution to it.
I also have the same issue with my GUI.
Marios Hadjipanayi
Marios Hadjipanayi le 25 Sep 2021
Déplacé(e) : Adam Danz le 3 Oct 2022
I have this problem too, please if anyone can help
I have the problem too, only worse: once the mouse enters the window, the processing drops 90% ish, and doesn't recover, even when the mouse has left the window!
I am using Matlab 2022b, but the problem has been here for at least 5 years. Never found a solution... Help appreciated!
There should be a simple way of switching off 'mouseover'...
Please contact tech support and attach your app and include instructions how to reproduce the problem. Feel free to include the URL of this thread.
I am having the same issue, is there any kind of solution by now?
I've a problem which probably has the same root. In my GUI I'm updating an image within an axes (also at a resaonable slow frame rate - 4 FPS) and if I hover it with mouse during such update, depending on the moment, it fails updating resulting in blank image. I'm not creating an object, but just changing its attribute .CData. All the underlaying data are safe, so I can't catch any issue to solve. I've also disabled axes Interactions and made axes toolbar not visible, but it didn't help.
Please help.

Connectez-vous pour commenter.

Réponses (1)

I had a similar problem while plotting data that was streaming in real time. Any movement of the mouse over the uiaxes interuppted the plotting. After searching online for how others addressed the issue, I found that the combination of uiaxes settings illustrated in the following code snippet worked perfectly for my application.
%
f = uifigure();
my_axis = uiaxes(f);
my_axis.XLimitMethod = 'tight';
my_axis.Interactions = [];
my_axis.PickableParts = 'none';
my_axis.HitTest = 'off';
I hope this works for you!

3 commentaires

thanks! That works! it still freezes, when the mouse moves, but will resume when still. It does the job! :)
BTW, I also found it necessary to initialize a single graphics object (an image in your case) prior to streaming and then update that objects properties during animation rather than creating a new object on each iteration. It speeds up plotting dramatically and (as you mention above) reduces teh impact of callbacks to mouse move events.
Thank you. Works like a charm.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Produits

Version

R2020a

Question posée :

le 30 Déc 2020

Commenté :

le 28 Juil 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by