Bug in accessibility & unfocusAllComponents()?

It seems the recent addition of accessibility has introduced a bug or a breaking change in the way the focus for components is handled. It results in Logic X freezing indefinitely.

Apparently the call to unfocusAllComponents() can sometimes result in endless recursion. That problem was not present in JUCE 6.0.7. It is also gone, if you call setAccessible(false); on the main component.

I noticed that in my text editor.
I am deriving from TextEditor and I am calling unfocusAllComponents() from the overriden focusGained() function. I.e. I am doing something like this:

void DerivedTextEditor::focusGained(FocusChangeType reasonForChange)
{
    // Don't allow internal "grabKeyboardFocus" functions to activate focus.
    // Because for some reason those are also called, when a popup is dismissed.
    if (reasonForChange == FocusChangeType::focusChangedDirectly)
        unfocusAllComponents();
    
    TextEditor::focusGained(reasonForChange);
}

I know that it is a bit strange, to call unfocusAllComponents from a focusGained method. But I needed that to prevent unwanted focus gains. And I think and hope that it is legal to do so? It worked fine before accessibility was introduced. And it also works fine, if you turn off accessibility by calling setAccessible(false); on the AudioProcessorEditor

You can reproduce the problem with the attached JUCE project.

  1. Set the target to AU and debug the AU under Logic X.
  2. In Logic X create an instance of the the DebugPlugin
  3. Open the GUI of the DebugPlugin → Logic X freezes.
  4. If you now press “Stop Debugging” you get a crash report where you can see a very deep recursion.

I have attached the JUCE project and the crash report.

I am using JUCE 6.1.2 under OSX 11.5.2 with Logic X 10.6.0

FocusFreezeCrash.txt (231.7 KB)

JUCE_Project.zip (28.9 KB)

1 Like

Thanks for reporting. There is a fix for this on the develop branch now:

Hi Ed,
Thanks for fixing.
I can confirm that it works for me now :slight_smile: