Browse Source

Added some macros for asserting when functions are called in an unsafe manner outside the message thread.

tags/2021-05-28
jules 7 years ago
parent
commit
5979288706
29 changed files with 115 additions and 69 deletions
  1. +2
    -2
      extras/Projucer/Source/Licenses/jucer_LicenseController.cpp
  2. +1
    -1
      extras/Projucer/Source/Licenses/jucer_LicenseThread.h
  3. +1
    -1
      extras/Projucer/Source/LiveBuildEngine/jucer_ActivityList.h
  4. +1
    -1
      extras/Projucer/Source/LiveBuildEngine/jucer_ErrorList.h
  5. +2
    -2
      modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp
  6. +3
    -5
      modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm
  7. +1
    -1
      modules/juce_audio_processors/format/juce_AudioPluginFormat.cpp
  8. +2
    -2
      modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp
  9. +2
    -2
      modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp
  10. +1
    -1
      modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp
  11. +0
    -3
      modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp
  12. +2
    -2
      modules/juce_events/broadcasters/juce_ActionBroadcaster.cpp
  13. +2
    -2
      modules/juce_events/broadcasters/juce_AsyncUpdater.cpp
  14. +4
    -4
      modules/juce_events/broadcasters/juce_ChangeBroadcaster.cpp
  15. +1
    -1
      modules/juce_events/messages/juce_MessageListener.cpp
  16. +16
    -0
      modules/juce_events/messages/juce_MessageManager.cpp
  17. +34
    -0
      modules/juce_events/messages/juce_MessageManager.h
  18. +1
    -1
      modules/juce_events/native/juce_android_Messaging.cpp
  19. +1
    -1
      modules/juce_events/timers/juce_Timer.cpp
  20. +1
    -1
      modules/juce_gui_basics/commands/juce_ApplicationCommandManager.cpp
  21. +19
    -17
      modules/juce_gui_basics/components/juce_Component.cpp
  22. +1
    -1
      modules/juce_gui_basics/components/juce_ModalComponentManager.cpp
  23. +5
    -5
      modules/juce_gui_basics/desktop/juce_Desktop.cpp
  24. +3
    -3
      modules/juce_gui_basics/desktop/juce_Displays.cpp
  25. +4
    -5
      modules/juce_gui_basics/juce_gui_basics.cpp
  26. +1
    -1
      modules/juce_gui_basics/native/juce_android_Windowing.cpp
  27. +2
    -2
      modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp
  28. +1
    -1
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp
  29. +1
    -1
      modules/juce_gui_basics/windows/juce_ThreadWithProgressWindow.cpp

+ 2
- 2
extras/Projucer/Source/Licenses/jucer_LicenseController.cpp View File

@@ -153,7 +153,7 @@ void LicenseController::startWebviewIfNeeded()
void LicenseController::logout()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
#if ! JUCER_ENABLE_GPL_MODE
thread.reset();
@@ -169,7 +169,7 @@ void LicenseController::logout()
void LicenseController::chooseNewLicense()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
#if ! JUCER_ENABLE_GPL_MODE
thread.reset();


+ 1
- 1
extras/Projucer/Source/Licenses/jucer_LicenseThread.h View File

@@ -35,7 +35,7 @@ struct NetWorkerThread : public Thread,
~NetWorkerThread()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
signalThreadShouldExit();
cancelPendingUpdate();


+ 1
- 1
extras/Projucer/Source/LiveBuildEngine/jucer_ActivityList.h View File

@@ -105,7 +105,7 @@ private:
static void checkThread()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ActivityList)


+ 1
- 1
extras/Projucer/Source/LiveBuildEngine/jucer_ErrorList.h View File

@@ -114,7 +114,7 @@ private:
static void checkThread()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ErrorList)


+ 2
- 2
modules/juce_audio_devices/native/juce_mac_CoreMidi.cpp View File

@@ -222,7 +222,7 @@ namespace CoreMidiHelpers
{
// It seems that OSX can be a bit picky about the thread that's first used to
// search for devices. It's safest to use the message thread for calling this.
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
StringArray s;
enableSimulatorMidiSession();
@@ -268,7 +268,7 @@ namespace CoreMidiHelpers
{
// Since OSX 10.6, the MIDIClientCreate function will only work
// correctly when called from the message thread!
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
enableSimulatorMidiSession();


+ 3
- 5
modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm View File

@@ -1740,15 +1740,13 @@ public:
JuceAUViewController (AUViewController<AUAudioUnitFactory>* p)
: myself (p)
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_AudioUnitv3;
initialiseJuce_GUI();
}
~JuceAUViewController()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
if (processorHolder != nullptr)
JuceAudioUnitv3::removeEditor (getAudioProcessor());
@@ -1757,7 +1755,7 @@ public:
//==============================================================================
void loadView()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
if (AudioProcessor* p = createPluginFilterOfType (AudioProcessor::wrapperType_AudioUnitv3))
{
@@ -1894,7 +1892,7 @@ private:
//==============================================================================
AUAudioUnit* createAudioUnitOnMessageThread (const AudioComponentDescription& descr, NSError** error)
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
[myself view]; // this will call [view load] and ensure that the AudioProcessor has been instantiated


+ 1
- 1
modules/juce_audio_processors/format/juce_AudioPluginFormat.cpp View File

@@ -199,7 +199,7 @@ void AudioPluginFormat::createPluginInstanceOnMessageThread (const PluginDescrip
AudioPluginFormat::InstantiationCompletionCallback* callback)
{
jassert (callback != nullptr);
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
//==============================================================================


+ 2
- 2
modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp View File

@@ -1536,7 +1536,7 @@ struct VST3ComponentHolder
// On Windows it's highly advisable to create your plugins using the message thread,
// because many plugins need a chance to create HWNDs that will get their messages
// delivered by the main message thread, and that's not possible from a background thread.
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
#endif
factory = ComSmartPtr<IPluginFactory> (module->getPluginFactory());
@@ -1749,7 +1749,7 @@ public:
// On Windows it's highly advisable to create your plugins using the message thread,
// because many plugins need a chance to create HWNDs that will get their messages
// delivered by the main message thread, and that's not possible from a background thread.
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
#endif
if (! holder->initialise())


+ 2
- 2
modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp View File

@@ -1210,7 +1210,7 @@ struct VSTPluginInstance : public AudioPluginInstance,
// because many plugins need a chance to create HWNDs that will get their
// messages delivered by the main message thread, and that's not possible from
// a background thread.
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
#endif
JUCE_VST_LOG ("Initialising VST: " + vstModule->pluginName + " (" + getVersion() + ")");
@@ -3216,7 +3216,7 @@ private:
{
// You shouldn't end up hitting this assertion unless the host is trying to do GUI
// cleanup on a non-GUI thread.. If it does that, bad things could happen in here..
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_VST_LOG ("Closing VST UI: " + plugin.getName());
isOpen = false;


+ 1
- 1
modules/juce_audio_utils/gui/juce_AudioThumbnail.cpp View File

@@ -642,7 +642,7 @@ void AudioThumbnail::saveTo (OutputStream& output) const
//==============================================================================
bool AudioThumbnail::setDataSource (LevelDataSource* newSource)
{
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
numSamplesFinished = 0;


+ 0
- 3
modules/juce_blocks_basics/topology/juce_PhysicalTopologySource.cpp View File

@@ -23,9 +23,6 @@
namespace juce
{
#define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED \
jassert (juce::MessageManager::getInstance()->currentThreadHasLockedMessageManager());
#if DUMP_BANDWIDTH_STATS
namespace
{


+ 2
- 2
modules/juce_events/broadcasters/juce_ActionBroadcaster.cpp View File

@@ -52,13 +52,13 @@ private:
ActionBroadcaster::ActionBroadcaster()
{
// are you trying to create this object before or after juce has been intialised??
jassert (MessageManager::getInstanceWithoutCreating() != nullptr);
JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
}
ActionBroadcaster::~ActionBroadcaster()
{
// all event-based objects must be deleted BEFORE juce is shut down!
jassert (MessageManager::getInstanceWithoutCreating() != nullptr);
JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
}
void ActionBroadcaster::addActionListener (ActionListener* const listener)


+ 2
- 2
modules/juce_events/broadcasters/juce_AsyncUpdater.cpp View File

@@ -63,7 +63,7 @@ void AsyncUpdater::triggerAsyncUpdate()
{
// If you're calling this before (or after) the MessageManager is
// running, then you're not going to get any callbacks!
jassert (MessageManager::getInstanceWithoutCreating() != nullptr);
JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
if (activeMessage->shouldDeliver.compareAndSetBool (1, 0))
if (! activeMessage->post())
@@ -79,7 +79,7 @@ void AsyncUpdater::cancelPendingUpdate() noexcept
void AsyncUpdater::handleUpdateNowIfNeeded()
{
// This can only be called by the event thread.
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
if (activeMessage->shouldDeliver.exchange (0) != 0)
handleAsyncUpdate();


+ 4
- 4
modules/juce_events/broadcasters/juce_ChangeBroadcaster.cpp View File

@@ -36,7 +36,7 @@ void ChangeBroadcaster::addChangeListener (ChangeListener* const listener)
{
// Listeners can only be safely added when the event thread is locked
// You can use a MessageManagerLock if you need to call this from another thread.
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
changeListeners.add (listener);
}
@@ -45,7 +45,7 @@ void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener)
{
// Listeners can only be safely removed when the event thread is locked
// You can use a MessageManagerLock if you need to call this from another thread.
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
changeListeners.remove (listener);
}
@@ -54,7 +54,7 @@ void ChangeBroadcaster::removeAllChangeListeners()
{
// Listeners can only be safely removed when the event thread is locked
// You can use a MessageManagerLock if you need to call this from another thread.
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
changeListeners.clear();
}
@@ -68,7 +68,7 @@ void ChangeBroadcaster::sendChangeMessage()
void ChangeBroadcaster::sendSynchronousChangeMessage()
{
// This can only be called by the event thread.
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
broadcastCallback.cancelPendingUpdate();
callListeners();


+ 1
- 1
modules/juce_events/messages/juce_MessageListener.cpp View File

@@ -35,7 +35,7 @@ void Message::messageCallback()
MessageListener::MessageListener() noexcept
{
// Are you trying to create a messagelistener before or after juce has been intialised??
jassert (MessageManager::getInstanceWithoutCreating() != nullptr);
JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
}
MessageListener::~MessageListener()


+ 16
- 0
modules/juce_events/messages/juce_MessageManager.cpp View File

@@ -231,6 +231,22 @@ bool MessageManager::currentThreadHasLockedMessageManager() const noexcept
return thisThread == messageThreadId || thisThread == threadWithLock.get();
}
bool MessageManager::existsAndIsLockedByCurrentThread() noexcept
{
if (auto i = getInstanceWithoutCreating())
return i->currentThreadHasLockedMessageManager();
return false;
}
bool MessageManager::existsAndIsCurrentThread() noexcept
{
if (auto i = getInstanceWithoutCreating())
return i->isThisTheMessageThread();
return false;
}
//==============================================================================
//==============================================================================
/* The only safe way to lock the message thread while another thread does


+ 34
- 0
modules/juce_events/messages/juce_MessageManager.h View File

@@ -147,6 +147,16 @@ public:
*/
bool currentThreadHasLockedMessageManager() const noexcept;
/** Returns true if there's an instance of the MessageManager, and if the current thread
has the lock on it.
*/
static bool existsAndIsLockedByCurrentThread() noexcept;
/** Returns true if there's an instance of the MessageManager, and if the current thread
is running it.
*/
static bool existsAndIsCurrentThread() noexcept;
//==============================================================================
/** Sends a message to all other JUCE applications that are running.
@@ -462,4 +472,28 @@ private:
JUCE_DECLARE_NON_COPYABLE (MessageManagerLock)
};
//==============================================================================
/** This macro is used to catch unsafe use of functions which expect to only be called
on the message thread, or when a MessageManagerLock is in place.
It will also fail if you try to use the function before the message manager has been
created, which could happen if you accidentally invoke it during a static constructor.
*/
#define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED \
jassert (juce::MessageManager::existsAndIsLockedByCurrentThread());
/** This macro is used to catch unsafe use of functions which expect to only be called
on the message thread.
It will also fail if you try to use the function before the message manager has been
created, which could happen if you accidentally invoke it during a static constructor.
*/
#define JUCE_ASSERT_MESSAGE_THREAD \
jassert (juce::MessageManager::existsAndIsCurrentThread());
/** This macro is used to catch unsafe use of functions which expect to not be called
outside the lifetime of the MessageManager.
*/
#define JUCE_ASSERT_MESSAGE_MANAGER_EXISTS \
jassert (juce::MessageManager::getInstanceWithoutCreating() != nullptr);
} // namespace juce

+ 1
- 1
modules/juce_events/native/juce_android_Messaging.cpp View File

@@ -78,7 +78,7 @@ struct AndroidMessageQueue : private Android::Runnable
~AndroidMessageQueue()
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
clearSingletonInstance();
}


+ 1
- 1
modules/juce_events/timers/juce_Timer.cpp View File

@@ -324,7 +324,7 @@ void Timer::startTimer (int interval) noexcept
{
// If you're calling this before (or after) the MessageManager is
// running, then you're not going to get any timer callbacks!
jassert (MessageManager::getInstanceWithoutCreating() != nullptr);
JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
const TimerThread::LockType::ScopedLockType sl (TimerThread::lock);


+ 1
- 1
modules/juce_gui_basics/commands/juce_ApplicationCommandManager.cpp View File

@@ -185,7 +185,7 @@ bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::Invocati
{
// This call isn't thread-safe for use from a non-UI thread without locking the message
// manager first..
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
bool ok = false;
ApplicationCommandInfo commandInfo (0);


+ 19
- 17
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -456,7 +456,7 @@ void Component::setName (const String& name)
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
if (componentName != name)
{
@@ -482,7 +482,7 @@ void Component::setVisible (bool 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
const WeakReference<Component> safePointer (this);
flags.visibleFlag = shouldBeVisible;
@@ -562,7 +562,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
if (isOpaque())
styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
@@ -663,7 +663,7 @@ void Component::removeFromDesktop()
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
if (flags.hasHeavyweightPeerFlag)
{
@@ -839,7 +839,7 @@ void Component::toFront (bool setAsForeground)
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
if (flags.hasHeavyweightPeerFlag)
{
@@ -1030,7 +1030,7 @@ void Component::setBounds (int x, int y, int w, int h)
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
if (w < 0) w = 0;
if (h < 0) h = 0;
@@ -1344,7 +1344,7 @@ void Component::addChildComponent (Component& child, int zOrder)
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
jassert (this != &child); // adding a component to itself!?
@@ -1422,7 +1422,7 @@ Component* Component::removeChildComponent (int index, bool sendParentEvents, bo
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN
auto* child = childComponentList [index];
@@ -1609,7 +1609,7 @@ void Component::enterModalState (bool shouldTakeKeyboardFocus,
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
if (! isCurrentlyModal (false))
{
@@ -1786,7 +1786,7 @@ void Component::internalRepaintUnchecked (Rectangle<int> area, bool isEntireComp
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
if (flags.visibleFlag)
{
@@ -2166,10 +2166,12 @@ void Component::addComponentListener (ComponentListener* newListener)
{
// 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.
#if JUCE_DEBUG || JUCE_LOG_ASSERTIONS
#if JUCE_DEBUG || JUCE_LOG_ASSERTIONS
if (getParentComponent() != nullptr)
ASSERT_MESSAGE_MANAGER_IS_LOCKED;
#endif
{
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
}
#endif
componentListeners.add (newListener);
}
@@ -2220,7 +2222,7 @@ void Component::addMouseListener (MouseListener* newListener,
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
// If you register a component as a mouselistener for itself, it'll receive all the events
// twice - once via the direct callback that all components get anyway, and then again as a listener!
@@ -2236,7 +2238,7 @@ void Component::removeMouseListener (MouseListener* listenerToRemove)
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
if (mouseListeners != nullptr)
mouseListeners->removeListener (listenerToRemove);
@@ -2736,7 +2738,7 @@ void Component::grabKeyboardFocus()
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
grabFocusInternal (focusChangedDirectly, true);
@@ -2751,7 +2753,7 @@ void Component::moveKeyboardFocusToSibling (bool moveToNext)
{
// 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.
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
if (parentComponent != nullptr)
{


+ 1
- 1
modules/juce_gui_basics/components/juce_ModalComponentManager.cpp View File

@@ -254,7 +254,7 @@ bool ModalComponentManager::cancelAllModalComponents()
int ModalComponentManager::runEventLoopForCurrentComponent()
{
// This can only be run from the message thread!
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
int returnValue = 0;


+ 5
- 5
modules/juce_gui_basics/desktop/juce_Desktop.cpp View File

@@ -70,7 +70,7 @@ Component* Desktop::getComponent (int index) const noexcept
Component* Desktop::findComponentAt (Point<int> screenPosition) const
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
for (int i = desktopComponents.size(); --i >= 0;)
{
@@ -105,7 +105,7 @@ LookAndFeel& Desktop::getDefaultLookAndFeel() noexcept
void Desktop::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel)
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
currentLookAndFeel = newDefaultLookAndFeel;
for (int i = getNumComponents(); --i >= 0;)
@@ -216,14 +216,14 @@ ListenerList<MouseListener>& Desktop::getMouseListeners()
void Desktop::addGlobalMouseListener (MouseListener* listener)
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
mouseListeners.add (listener);
resetTimer();
}
void Desktop::removeGlobalMouseListener (MouseListener* listener)
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
mouseListeners.remove (listener);
resetTimer();
}
@@ -323,7 +323,7 @@ bool Desktop::isOrientationEnabled (DisplayOrientation orientation) const noexce
void Desktop::setGlobalScaleFactor (float newScaleFactor) noexcept
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
if (masterScaleFactor != newScaleFactor)
{


+ 3
- 3
modules/juce_gui_basics/desktop/juce_Displays.cpp View File

@@ -138,7 +138,7 @@ Point<ValueType> Displays::logicalToPhysical (Point<ValueType> point, const Disp
const Displays::Display& Displays::getMainDisplay() const noexcept
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
for (auto& d : displays)
if (d.isMain)
@@ -151,7 +151,7 @@ const Displays::Display& Displays::getMainDisplay() const noexcept
RectangleList<int> Displays::getRectangleList (bool userAreasOnly) const
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
RectangleList<int> rl;
for (auto& d : displays)
@@ -197,7 +197,7 @@ bool operator!= (const Displays::Display& d1, const Displays::Display& d2) noexc
// Deprecated method
const Displays::Display& Displays::getDisplayContaining (Point<int> position) const noexcept
{
ASSERT_MESSAGE_MANAGER_IS_LOCKED
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
auto* best = &displays.getReference (0);
auto bestDistance = std::numeric_limits<int>::max();


+ 4
- 5
modules/juce_gui_basics/juce_gui_basics.cpp View File

@@ -139,11 +139,10 @@
#include <set>
//==============================================================================
#define ASSERT_MESSAGE_MANAGER_IS_LOCKED \
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
#define ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN \
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager() || getPeer() == nullptr);
#define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED_OR_OFFSCREEN \
jassert ((MessageManager::getInstanceWithoutCreating() != nullptr \
&& MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager()) \
|| getPeer() == nullptr);
namespace juce
{


+ 1
- 1
modules/juce_gui_basics/native/juce_android_Windowing.cpp View File

@@ -74,7 +74,7 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* en
jassertfalse; // you must supply an application object for an android app!
}
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
}
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, suspendApp, void, (JNIEnv* env, jobject))


+ 2
- 2
modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp View File

@@ -1051,7 +1051,7 @@ public:
isAlwaysOnTop (comp.isAlwaysOnTop())
{
// it's dangerous to create a window on a thread other than the message thread..
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
display = XWindowSystem::getInstance()->displayRef();
@@ -1097,7 +1097,7 @@ public:
~LinuxComponentPeer()
{
// it's dangerous to delete a window on a thread other than the message thread..
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
#if JUCE_X11_SUPPORTS_XEMBED
juce_handleXEmbedEvent (this, nullptr);


+ 1
- 1
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -1275,7 +1275,7 @@ public:
void setTitle (const String& title) override
{
// Unfortunately some ancient bits of win32 mean you can only perform this operation from the message thread.
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
SetWindowText (hwnd, title.toWideCharPointer());
}


+ 1
- 1
modules/juce_gui_basics/windows/juce_ThreadWithProgressWindow.cpp View File

@@ -59,7 +59,7 @@ ThreadWithProgressWindow::~ThreadWithProgressWindow()
void ThreadWithProgressWindow::launchThread (int priority)
{
jassert (MessageManager::getInstance()->isThisTheMessageThread());
JUCE_ASSERT_MESSAGE_THREAD
startThread (priority);
startTimer (100);


Loading…
Cancel
Save