I have a custom class for my animated knobs (derived from Slider) and I use shift+double click to show a text editor to enter the parameter’s value. I recently moved from JUCE 6.0.8 to 6.1.5 and now I’m getting a crash as soon as I perform shit+doubleClick on my knobs.
I’m getting an assertion failure in juce_WeakReference coming from Label::showEditor() when it calls “enterModalState(false)”. Looks like the parent component goes nullptr before showing the label. This is called from the main Slider class’s pimpl.
Modal loops are permitted and I’m setting the textBox when I need to show it:
DBG("shift + mouseDoubleClick");
setTextBoxStyle(Slider::TextBoxBelow, false, 100, 40);
then I hide it after the value has been entered. As said, we had no problems before updating to J 6.1.5. I already tried looking into the breaking changes, but there’s no mention about any change made to the Slider class.
@reuk please, can you look into this? we have live products that are hitting this issue and we don’t want to bypass that feature at the moment.
Please check the behaviour on develop first. This may already have been fixed.
Tested with develop tip, still crashing.
Here’s attached an example project to replicate the issue, with a minimal replica of what we do.
Knob Test.zip (67.6 KB)
To replicate the crash, just hover on the knob, then shift+double click.
Thanks for providing a demo project, that’s very helpful to track down the issue.
It looks to me like the cause of the crash is a change that was made before 6.1.5 that is intended to keep calls to mouseEnter and mouseExit balanced when entering/exiting modal state. If the mouse is over a component that will be blocked by the new modal component, it is sent mouseExit, and when the modal state ends, the component now under the mouse is sent mouseEnter. This helps to avoid the case where components receive two calls to mouseEnter or mouseExit in a row.
In your editor, opening the text label causes the label to become modal. The mouse is over the slider, which would be blocked by the modal component, so the slider is sent a mouseExit. However, in the mouseExit callback, the text label is hidden again before the label manages to start its modal state, and further attempts to access the label result in a crash.
I’m not sure of the best course of action here. We can’t revert the new mouseEnter/mouseExit behaviour, because that would reintroduce the issue with unbalanced calls. However, we could add an assertion to
enterModalState to check that the modal component is still alive after sending the mouseExit.
In terms of a solution to the problem, you could try just avoiding calling
mouseExit. I don’t really understand how this is intended to work currently - when the label is open and modal, the slider won’t receive mouse events anyway, so this technique can’t be used to hide the text editor when the mouse moves outside the slider. Is this call intended to handle some other edge case? If not, I recommend removing it, and this should resolve the crash.
Thanks @reuk. I ended up creating a custom component acting as textbox entry and it works fine. No need to go in modal state. It’s just a hidden textEditor showing as an Editor’s child component when required. Works perfectly now.