Sluggish slider behavior when using repaint() in timer

I have a Component with several subcomponents. In subcomponent A, there is a time counter (like 00:00:00) that I’d like updated every x milliseconds. In subcomponent B, there is a JUCE slider. There is a lot more, but this is what matters. When I move the slider, the slider gets drawn quickly and the sliderValueChanged() callback shows me a lot of different values when I move from bottom to top.
But now when I start a timer (component A derives from the Timer class) and let’s say the timerCallback() is called every 125 milliseconds and move the slider, then the slider becomes very sluggish (the knob is drawn sluggish and only one or two values are received in sliderValueChanged() when moving from bottom to top). The timerCallback() contains a repaint(rect) where the rect contains the bounds of the time counter.

Removing repaint() makes the problem go away, so it is not the timer itself. I have put return; statements on the first line of all my paint() methods, so they don’t draw anything and that didn’t help. The sliderValueChanged() method does nothing more than print the value to logcat.

I’m on Android with JUCE 5.4.4.

Any thoughts?

Do you run Android app in release mode? Painting in debug will be very slow. Plus try to attach OpenGL context to component containing sliders, it will speed up rendering on Android.

I always run in release mode. And here I was thinking it was already using OpenGL! Hmm… how do I switch to OpenGL? The drawing of the slider is fast enough since if the timer is not running, it will draw very fast.

Create as class member OpenGLContext and then attach it Component.
OpenGLContext openGlContext;

OMG! Thanks a million! I just attached it to the topmost component and the problem is solved!

1 Like