Currently I’m configuring a plugin where when I double click the slider and it calls show editor on a label that appears on hover over the slider.
The labels are initialized like this:
addAndMakeVisible(label);
label->addListener(this);
/* Set labels to be not enabled and not visible by default */
label->setEnabled(false);
label->setVisible(false);
label->setEditable(true);
in the hook for the mouse down event the function is called like this:
if (e.getNumberOfClicks() == 2)
{
juce::Slider *slider = findSliderFromComponent(e.eventComponent);
if (slider != nullptr && slidersArray.contains(slider))
{
auto index = slidersArray.indexOf(slider);
auto *label = labelsArray.getUnchecked(index);
label->setVisible(true);
label->setEnabled(true);
label->showEditor();
}
else
{
/* Slider not found */
}
}
The specific error on the stack takes me into juce component class on line 613 which is this:
if( ! flags.visibleFlag)
return false;
and raises an error saying "JUCE Message Thread (1): EXC_BAD_ACCESS (code=1, address=0xd8)"
My guess is the texteditor isn’t initializing properly but I’m not sure how to fix this. I hope this post was detailed enough. First time posting so apologies if I messed something up.
Thanks for the reply! Already done in the header. After stepping through the debugger it looks like in the function showEditor the editor becomes a null pointer after calling enterModalState(false); which is odd. I’m not entirely sure what enterModalState does. If I comment out the line enterModalState(false) everything works.
Why do need to you call on text editor enterModalState?
I think editable Label is simple enough to use, you don’t have to do anything with its text editor. unless you need to convert or calculate thing from strings, or do some tricky keyboard input filtering.
Have you checked that labelsArray is at least as large as index when you call getUnchecked? Is the label at that index definitely initialised correctly?
The cause was that Label::showEditor() calls enterModalState(false), that calls ComponentHelpers::sendMouseEventToComponentsThatAreBlockedByModal (*this, &Component::internalMouseExit);
That calls mouse exit to the slider that uses the label, and probably you hide the label on that mouseExit. Then the Label::showEditor() continues but the label is not visible, and crashes.
I solved it by having a bool flag to indicate whether the label has the editor shown, and use it to avoid calling label->hideEditor() in the mouseExit call.