Browse Source

Added some assertions to catch event-based objects being used before the message manager has been initialised

tags/2021-05-28
jules 9 years ago
parent
commit
c2bd54aefc
2 changed files with 12 additions and 4 deletions
  1. +8
    -4
      modules/juce_events/broadcasters/juce_AsyncUpdater.cpp
  2. +4
    -0
      modules/juce_events/timers/juce_Timer.cpp

+ 8
- 4
modules/juce_events/broadcasters/juce_AsyncUpdater.cpp View File

@@ -33,10 +33,8 @@ public:
owner.handleAsyncUpdate();
}
Atomic<int> shouldDeliver;
private:
AsyncUpdater& owner;
Atomic<int> shouldDeliver;
JUCE_DECLARE_NON_COPYABLE (AsyncUpdaterMessage)
};
@@ -53,13 +51,19 @@ AsyncUpdater::~AsyncUpdater()
// pending on the main event thread - that's pretty dodgy threading, as the callback could
// happen after this destructor has finished. You should either use a MessageManagerLock while
// deleting this object, or find some other way to avoid such a race condition.
jassert ((! isUpdatePending()) || MessageManager::getInstance()->currentThreadHasLockedMessageManager());
jassert ((! isUpdatePending())
|| MessageManager::getInstanceWithoutCreating() == nullptr
|| MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager());
activeMessage->shouldDeliver.set (0);
}
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);
if (activeMessage->shouldDeliver.compareAndSetBool (1, 0))
if (! activeMessage->post())
cancelPendingUpdate(); // if the message queue fails, this avoids getting


+ 4
- 0
modules/juce_events/timers/juce_Timer.cpp View File

@@ -294,6 +294,10 @@ Timer::~Timer()
void Timer::startTimer (const 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);
const TimerThread::LockType::ScopedLockType sl (TimerThread::lock);
if (timerPeriodMs == 0)


Loading…
Cancel
Save