Strange messageManagerLock problem


Got a strange problem in 146 (on Windows XP). I saw that in 147 you wrote that in revision 697 you rewrote MessageManagerLock to “hopefully make it bulletproof”. Might my problem here be related to this and how could I resolve it without using 147?

Here’s what the initial calling code makes:

MainAppWindow::~MainAppWindow() { LookAndFeel::setDefaultLookAndFeel(0);

Here’s where the problem occurs:

void Component::setVisible (bool shouldBeVisible) { if (flags.visibleFlag != shouldBeVisible) { // if component methods are being called from threads other than the message // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe. checkMessageManagerIsLocked

Call stack:

start.exe!juce::Component::setVisible(bool shouldBeVisible=true) Line 223 + 0x4e C++
start.exe!juce::Button::setVisible(bool shouldBeVisible=true) Line 480 C++
start.exe!juce::Component::addAndMakeVisible(juce::Component * const child=0x107b8e70, int zOrder=0xffffffff) Line 1223 + 0xf C++
start.exe!juce::DocumentWindow::lookAndFeelChanged() Line 297 C++
start.exe!juce::Component::sendLookAndFeelChange() Line 1863 + 0xd C++
start.exe!juce::LookAndFeel::setDefaultLookAndFeel(juce::LookAndFeel * newDefaultLookAndFeel=0x00326b60) Line 270 C++
start.exe!MainAppWindow::~MainAppWindow() Line 79 + 0x7 C++
start.exe!MainAppWindow::`scalar deleting destructor’() + 0x2b C++
start.exe!AppClass::shutdown() Line 85 + 0x35 C++
start.exe!juce::JUCEApplication::shutdownAppAndClearUp(const bool useMaximumForce=false) Line 245 + 0xd C++
start.exe!juce::JUCEApplication::main(juce::String & commandLine={…}, juce::JUCEApplication * const app=0x00324ed8) Line 227 + 0x9 C++
start.exe!WinMain(int __formal=0x00400000, int __formal=0x00400000, const char * commandLine=0x00141f09, int __formal=0x00400000) Line 120 + 0xa0 C++
start.exe!WinMainCRTStartup() Line 390 + 0x39 C


Sounds like you just need to put a messagemanager lock around your shutdown code. In the newest code that’s not needed because anything happening on the message thread is implicitly locked, but in the older stuff it’s not.


Ok, where shall I exactly put this lock? I thought the shutdown is called from the GUI Thread anyway!?


Put it in your MainAppWindow destructor. It is called on the message thread, but adding the lock avoid the assertion happening. Like I say, all these problems go away with my latest changes to the way it locks.