Orientation unknow error in juce initialisation on iPhone

I’m using juce inside an iPhone application based on the MMI build with Interface builder.

The main procedure looks like this

[i]int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

ScopedJuceInitialiser_GUI jucePlugin;

int retVal = UIApplicationMain(argc, argv, nil, nil);


When the application starts, an exception is triggered in the juce constructor

#2 0x0036ca2f in juce::UIViewComponentPeer::realScreenPosToRotated at juce_ios_UIViewComponentPeer.mm:215
#3 0x00348458 in juce::juce_updateMultiMonitorInfo at juce_ios_UIViewComponentPeer.mm:1003
#4 0x0022f060 in juce::desktop::refreshMonitorSizes at juce_Desktop.cpp:77
#5 0x0022f338 in juce::desktop::Desktop at juce_Desktop.cpp:44
#6 0x0022f4ae in juce::desktop::getInstance at juce_Desktop.cpp:60
#7 0x0022faa0 in juce::LookAndFeel::setDefaultLookAndFeel at juce_LookAndFeel.cpp:375
#8 0x0008dc2e in juce::initialiseJuce_GUI at juce_Initialisation.cpp:129
#9 0x001e5955 in juce::ScopedJuceInitialiser_GUI::ScopedJuceInitialiser_GUI at juce_Initialisation.h:122

The orientation is unknown in this method :

const Rectangle realScreenPosToRotated (const Rectangle& r)
const Rectangle screen (convertToRectInt ([[UIScreen mainScreen] bounds]));

    switch ([[UIApplication sharedApplication] statusBarOrientation])
        case UIInterfaceOrientationPortrait:
            return r;

        case UIInterfaceOrientationPortraitUpsideDown:
            return Rectangle<int> (screen.getWidth() - r.getRight(), screen.getHeight() - r.getBottom(),
                                   r.getWidth(), r.getHeight());

        case UIInterfaceOrientationLandscapeLeft:
            return Rectangle<int> (screen.getHeight() - r.getBottom(), r.getX(),
                                   r.getHeight(), r.getWidth());

        case UIInterfaceOrientationLandscapeRight:
            return Rectangle<int> (r.getY(), screen.getWidth() - r.getRight(),
                                   r.getHeight(), r.getWidth());

default: jassertfalse; // unknown orientation!

This happens on the last juce version.

Thanks for the help.

That’s a bit odd, there are only 4 possible values, and all of them are covered correctly by the switch statement. I added the assertion in case any new values were added in future, but according to the docs, that’s not happened. I guess it’s safe just to ignore the assertion, in which case it’ll just assume it’s in portrait mode…

Maybe the orientation is not yet initialized as the UIApplicationMain is not yet started

Yes, quite possibly. I don’t think this is a bug in the juce code anyway. I guess you can change your startup code or just ignore the assertion.

Thanks for this very fast answer.