mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-22 01:34:21 +00:00
MidiDeviceListConnectionBroadcaster: Avoid constructing MessageManager on incorrect thread
Previously, if the very first call to MidiDeviceListConnectionBroadcaster::get() happened on a background thread (which could happen on macOS in response to a MIDI setup configuration change), then MessageManager::getInstance and getAvailableDevices could be called on that same thread. With this change in place, midi change notifications will be ignored if there's no message manager available, and getAvailableDevices will only be called on the message thread.
This commit is contained in:
parent
a889149cbd
commit
5c138561bb
1 changed files with 12 additions and 10 deletions
|
|
@ -57,20 +57,22 @@ public:
|
|||
|
||||
void notify()
|
||||
{
|
||||
if (MessageManager::getInstance()->isThisTheMessageThread())
|
||||
{
|
||||
cancelPendingUpdate();
|
||||
auto* mm = MessageManager::getInstanceWithoutCreating();
|
||||
|
||||
const State newState;
|
||||
if (mm == nullptr)
|
||||
return;
|
||||
|
||||
if (std::exchange (lastNotifiedState, newState) != newState)
|
||||
for (auto it = callbacks.begin(); it != callbacks.end();)
|
||||
NullCheckedInvocation::invoke ((it++)->second);
|
||||
}
|
||||
else
|
||||
if (! mm->isThisTheMessageThread())
|
||||
{
|
||||
triggerAsyncUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
cancelPendingUpdate();
|
||||
|
||||
if (auto prev = std::exchange (lastNotifiedState, State{}); prev != lastNotifiedState)
|
||||
for (auto it = callbacks.begin(); it != callbacks.end();)
|
||||
NullCheckedInvocation::invoke ((it++)->second);
|
||||
}
|
||||
|
||||
static auto& get()
|
||||
|
|
@ -108,7 +110,7 @@ private:
|
|||
}
|
||||
|
||||
std::map<MidiDeviceListConnection::Key, std::function<void()>> callbacks;
|
||||
State lastNotifiedState;
|
||||
std::optional<State> lastNotifiedState;
|
||||
MidiDeviceListConnection::Key key = 0;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue