Problems building from the command line on Mac


#1

Hi,

I'm trying to build a JUCE application from the command line (using Gradle) without the involvement of an XCode project. I get the program to build but when I run it there's no UI visible, just a bunch of error messages in the terminal:

➜  debug  ./AuraVis
JUCE v4.1.0
Feb 19 11:14:52  AuraVis[37760] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Feb 19 11:14:52  AuraVis[37760] <Warning>: Invalid Connection ID 0
Feb 19 11:14:52  AuraVis[37760] <Error>: Set a breakpoint at CGSLogError to catch errors as they are logged.
Feb 19 11:14:52  AuraVis[37760] <Error>: CGSSetWindowTitle: Invalid window
Feb 19 11:14:52  AuraVis[37760] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Feb 19 11:14:52  AuraVis[37760] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Feb 19 11:14:52  AuraVis[37760] <Warning>: Invalid Connection ID 0
Feb 19 11:14:52  AuraVis[37760] <Error>: CGSSetWindowTitle: Invalid window

Googling didn't turn up anything useful. Does anyone know what's wrong?

I'm aware there's a Gradle plugin that can build XCode projects from within Gradle, but since we're targeting Windows, too, we don't want to use it. On Windows our program works, by the way.

edit: this is from the system log:

19.02.16 12:14:52,264 launchservicesd[76]: SecTaskLoadEntitlements failed error=22
19.02.16 12:14:52,266 launchservicesd[76]: SecTaskLoadEntitlements failed error=22
19.02.16 12:14:52,279 AuraVis[38426]: CGSConnectionByID: 0 is not a valid connection ID.
19.02.16 12:14:52,279 AuraVis[38426]: Invalid Connection ID 0
19.02.16 12:14:52,280 AuraVis[38426]: Set a breakpoint at CGSLogError to catch errors as they are logged.
19.02.16 12:14:52,280 AuraVis[38426]: CGSSetWindowTitle: Invalid window
19.02.16 12:14:52,280 AuraVis[38426]: CGSConnectionByID: 0 is not a valid connection ID.
19.02.16 12:14:52,281 AuraVis[38426]: CGSConnectionByID: 0 is not a valid connection ID.
19.02.16 12:14:52,281 AuraVis[38426]: Invalid Connection ID 0
19.02.16 12:14:52,281 AuraVis[38426]: CGSSetWindowTitle: Invalid window

If more information is needed, let me know!

Thanks!


#2

Ok, I think I found the cause of the problem. In my main function I check the software license before starting the juce message loop (after creating a stack object of type ScopedJuceInitialiser_GUI). And the license check may display juce dialogs for error messages or for entering the license key. This apparently doesn't work on OS X. Displaying a NativeMessageBox causes no problems at this stage.

Is there something I can do to enable Juce dialogs before the message loop (do they have their own internal message loop?) or is this simply not possible and will I have to move the license check to a later point in the program?


#3

Ok, here is how I solved my problem:

#if JUCE_MAC
    namespace juce {
        extern void initialiseNSApplication();
    }
#endif

static juce::JUCEApplicationBase* juce_CreateApplication() { return new AuraVisApplication(); }

int main(int argc, char* argv[])
{
    ScopedJuceInitialiser_GUI gui;

#if JUCE_MAC
    juce::initialiseNSApplication();
#endif

    /*
        ...code that displays Juce AlertWindows here, which was causing the problems...
    */

    juce::JUCEApplicationBase::createInstance = &juce_CreateApplication;
    return juce::JUCEApplicationBase::main (JUCE_MAIN_FUNCTION_ARGS);
}

Perhaps the right thing to do would be putting that call into ScopedJuceInitialiser_GUI, because that class is supposed to take care of UI initialisation.

Anyway, I'm glad I could find a solution and hope this message thread helps other people in the future.


#4

Personally, I'd recommend just doing the check asynchronously later on. It'll also make it more hassle for crackers to disassemble your licensing code :)