Issues latest dev branch - getMainDisplay()


#1

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.


#2

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?


#3

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:


#4

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.


#5

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
{
    ASSERT_MESSAGE_MANAGER_IS_LOCKED
    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


#6

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.


#7

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.


#8

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