On calling MenuBarModel::setMacMainMenu() (too early?)

5 posts / 0 new
Last post
TomSwirly
Offline
Last seen: 4 months 3 weeks ago
Joined: 8 Feb 2010 - 22:19
On calling MenuBarModel::setMacMainMenu() (too early?)

Hello, quickie Q here just to avoid going down a wrong path. Hope I didn't miss something when searching!

I'm calling MenuBarModel::setMacMainMenu() in the constructor of my DocumentWindow, and I get an immediate crash. The debugger gets a little confused around here, but it appears that deeper down, we're touching an uninitialized Array... but all my classes appear to be finished their construction and initialization...

Before I dig further, might I ask if calling MenuBarModel::setMacMainMenu() in the constructor is too early, and if so, what's the best way to do it? Or it's very useful just to know that I should be able to do it, so I can gird my loins and get dirty with the debugger.

Thanks in advance!

jules
Online
Last seen: 9 min 2 sec ago
Joined: 29 Apr 2013 - 18:37
Re: On calling MenuBarModel::setMacMainMenu() (too early?)

I think that when you call it, it'll immediately start trying to build a menu arrangement, which will invoke calls to the ApplicationCommand stuff to find out what's on there, and that'll probably try to call your not-ready-yet window object.

I typically call the setMainMenu things in JUCEApplication::initialise, after the main window has been created. I guess you could also safely call it before the window gets created, just not in the middle of creating it!

TomSwirly
Offline
Last seen: 4 months 3 weeks ago
Joined: 8 Feb 2010 - 22:19
Re: On calling MenuBarModel::setMacMainMenu() (too early?)

Good explanation!

And this opens a very interesting can of worms that's been in the back of my head. (whew, what a metaphor!)

My application has no main window - or at least, logically it has no main window. I'm now wondering if that does really work for Juce - because Windows applications need a main Window (is that true?)

Regardless, I have a clear workaround - call MenuBarModel::setMacMainMenu() from the code that creates my DocumentWindow.... thanks, as always!

[OK, this didn't actually work. :-D I'm still getting a crash in MenuBarModel::addListener() - it seems that the Array that contains listeners is corrupt or uninitialized because the crash is at Array::contains, and the underlying memory pointer seems bogus... however, this is low on my list of priorities for now. I'll repost in this thread when I've found a solution to it!)

jules
Online
Last seen: 9 min 2 sec ago
Joined: 29 Apr 2013 - 18:37
Re: On calling MenuBarModel::setMacMainMenu() (too early?)

Quote:
My application has no main window - or at least, logically it has no main window. I'm now wondering if that does really work for Juce - because Windows applications need a main Window (is that true?)

Well, there's nothing stopping you from running a windowless app in Windows, but it makes it a bit tricky to interact with it. You could always use a SystemTrayIconComponent though.

TomSwirly
Offline
Last seen: 4 months 3 weeks ago
Joined: 8 Feb 2010 - 22:19
Re: On calling MenuBarModel::setMacMainMenu() (too early?)

Eh, it sounds like a Bad Idea, though, doesn't it? Last thing I want to do is to confuse the poor user. I think we'll end up having a tiny "home window" with a few global controls on it.

I'll post here again when I resolve the MenuBarModel issue (I edited my previous post to include more info)... be well!