I’m facing a problem in managing a continuous thread in a sequencer with graphical events,
as anybody know, this is more than dangerous to modify graphic comps from your own made continuous thread…
So, i’m watching all my code to patch antwhere i had badly developped, calling some repaint() or setBounds() in my thread…
Then, I made my concerned components BOTH change listeners and broadcasters for themselves.
For instance :
My thread tells A to become blue, A do that :
You can try using WaitableEvent class, wait () for stopping the thread, after which you can perform the UI events. After that call signal ( ) to start the thread.
Is that ok for my case ?[quote]MessageManagerLock Class Reference
List of all members.
Detailed Description
Used to make sure that the calling thread has exclusive access to the message loop.
Because it’s not thread-safe to call any of the Component or other UI classes from threads other than the message thread, one of these objects can be used to lock the message loop and allow this to be done. The message thread will be suspended for the lifetime of the MessageManagerLock object, so create one on the stack like this:
[code] void MyThread::run()
{
someData = 1234;
const MessageManagerLock mmLock;
// the event loop will now be locked so it's safe to make a few calls..
myComponent->setBounds (newBounds);
myComponent->repaint();
// ..the event loop will now be unlocked as the MessageManagerLock goes out of scope
}[/code]
Obviously be careful not to create one of these and leave it lying around, or your app will grind to a halt!
Another caveat is that using this in conjunction with other CriticalSections can create lots of interesting ways of producing a deadlock! In particular, if your message thread calls stopThread() for a thread that uses these locks, you’ll get an (occasional) deadlock…
A mmlock isn’t needed in a timercallback, although it’s perfectly safe to use one there. If it’s crashing, it must be because you’re doing something with your own threads that’s messing it up.
It is legal inside an mmlock - there could theoretically be problems if the OS doesn’t like its repaint functions being called on other threads, but I’ve never seen a problem like that.
Many jassert are raised when I use simply mmLock as in the doc example :
[quote]
JUCE Assertion failure in /Developer/Library/Juce/build/macosx/…/…/src/juce_appframework/gui/components/juce_Component.cpp, line 221
JUCE Assertion failure in /Developer/Library/Juce/build/macosx/…/…/src/juce_appframework/gui/components/juce_Component.cpp, line 1641[/quote]
Someone knows why ?
i tried to delete the mmLock manually after using, but nothing changed.
If you read the assertion’s comment, you’ll see that it’s failing because it’s not locked. So you can’t have actually used an mmlock correctly. The fact that you mention deleting a lock indicates that you’re probably doing something silly, because the locks should be used as local stack objects, not heap objects.