ResizableWindow::setContentNonOwned() causes problems with ToggleButtons

In MainWindow (inherited from juce::DocumentWindow) I delete the old MainComponent and set a new one with ResizableWindow::setContentNonOwned(pointer, true), due to loading a new project file and me creating a completely new instance of the MainComponent.

What happens is that the graphics squeeze ever so slightly in the vertical direction that it’s barely noticeable. When I try clicking juce::ToggleButtons, many of them don’t respond at all and some respond when I click buttons below them. It seems that the ToggleButtons clickable areas have moved up from where their visuals are located.

The above seems to fix itself perfectly when I manually resize the window with a mouse. But nothing I do in the code seems to fix the issue. I’ve tried calling the following in various parts of the code:

setBounds()
resized()
parentSizeChanged()
parentHierarchyChanged()
childrenChanged()

So what is going on and how to fix that issue? What is the difference between using any (or all) of the above, compared to me grabbing the window with a mouse cursor and resizing it manually?

EDIT:
I added the following lines to the code and that seems to fix the problem:

        const auto bounds = getBounds();
        setBounds(0, 0, getWidth() - 1, getHeight() - 1);
        setBounds(bounds);

But the above is really a kludge fix which makes me shudder having it in the code. I couldn’t just set the bounds once due to JUCE optimizing the non changed bound resizing away. So I had to change the size to something different and then back to its original size. I hope there is a better way around this.

Which operating system do you experience this problem on?

macOS Catalina.

I was unable so far to guess what exactly may be happening in your case. I created a little example app, but this is not enough to create the situation that you have. You may want to give it a try, but my guess this won’t produce the issue on your machine either.

setContentNonOwned.zip (3.3 KB)

If you can modify it to a point where it produces the issue, I’ll help with figuring out a solution.

I’ll try to arrange time for the test this week.