Issues latest dev branch - getMainDisplay()


I just tried the latest dev but my application keeps hitting an asset here:

It appears to be triggered when I call centreWithSize() on a DocumentWindow. If I take that out it gets a little further before it’s hit again.

Of course the Projucer and other applications I’ve tried all work fine. FWIW, my app works fine with the latest Master branch.


All methods, that affect Components, especially placement and painting, have to be called on the MessageThread. So when your app calls centreWithSize(), is it possible, that this is not from the messageThread?
You should be able to get around that by calling via MessageManager::callAsync (...);

Actually, reading again, is it the ASSERT_MESSAGE_MANAGER_IS_LOCKED or the next line, that asserts?


It’s the jassert (displays.getReference(0).isMain);. Thanks I’ll take a look at the callAsync() method. It seems each time I update to a new version of JUCE I have to rewrite some of my bad code. I expect that by about 2025 my app will be completely bug free and ready for release :rofl:


Btw, I’m pretty sure centreWithSize() is being called from the message thread, but thanks for the heads up. Gives me something to look at.


Oh, in that case you are fine. I was only looking at the first assert (maybe because it was shouting in capitals at me :wink: )
To be honest, the method you linked in looks a bit like a placeholder to me, that survived from an early stage, unless there is reason for the assumption, that the first display should be the main display.

I assume it should look like:

const Displays::Display& Displays::getMainDisplay() const noexcept
    for (auto& display : displays)
        if (display.isMain)
            return display;

    return displays.getReference(0);

But I leave the final answer to @ed95 or @t0m, they are the experts there


Yeah, I think you’re right. Has last minute Friday evening commit written all over it :rofl: Your modified method should work fine for the time being. Thanks for that. Much appreciated.


What platform are you on? The method which calculates the displays should swap the main one so that’s it’s always first, but I can’t see any harm in making that method a bit more flexible.


Hi @ed95. I tried on Linux earlier. And just now I tried on Windows where it all works fine.


This issue is still present when I build my apps with 5.4.1 on Linux? I’m not sure why I’m hitting that assert. As much as I enjoy the irony of reading the //no main display! comment above the assert, on my main display, I’m at a loss to explain it. Removing the jassertfalse lets me get past it, but I’m worried it will come back to bite me later. Not a biggy, enjoy ADC, and let me know if you have any ideas as to why it might be happening.


That’s strange. I did make this change a few weeks ago which made the method a bit more forgiving if the displays are added in the wrong order:

But if you’re still hitting the assertion then that implies that no main display is being added at all. Which Linux distro are you using? I’ve tested it on Ubuntu 18.04 but can’t reproduce.


Thanks Ed, I’m using 17.04 but I’ll be updating to 18.04 which will probably resolve the issue.