Browse Source

Added activeEditorLock to AudioProcessor to replace callbackLock when accessing its activeEditor member to prevent priority inversion issues

tags/2021-05-28
ed 5 years ago
parent
commit
bad6500424
2 changed files with 22 additions and 9 deletions
  1. +15
    -5
      modules/juce_audio_processors/processors/juce_AudioProcessor.cpp
  2. +7
    -4
      modules/juce_audio_processors/processors/juce_AudioProcessor.h

+ 15
- 5
modules/juce_audio_processors/processors/juce_AudioProcessor.cpp View File

@@ -52,8 +52,12 @@ AudioProcessor::AudioProcessor (const BusesProperties& ioConfig)
AudioProcessor::~AudioProcessor()
{
// ooh, nasty - the editor should have been deleted before its AudioProcessor.
jassert (activeEditor == nullptr);
{
const ScopedLock sl (activeEditorLock);
// ooh, nasty - the editor should have been deleted before its AudioProcessor.
jassert (activeEditor == nullptr);
}
#if JUCE_DEBUG && ! JUCE_DISABLE_AUDIOPROCESSOR_BEGIN_END_GESTURE_CHECKING
// This will fail if you've called beginParameterChangeGesture() for one
@@ -803,14 +807,22 @@ void AudioProcessor::audioIOChanged (bool busNumberChanged, bool channelNumChang
//==============================================================================
void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) noexcept
{
const ScopedLock sl (callbackLock);
const ScopedLock sl (activeEditorLock);
if (activeEditor == editor)
activeEditor = nullptr;
}
AudioProcessorEditor* AudioProcessor::getActiveEditor() const noexcept
{
const ScopedLock sl (activeEditorLock);
return activeEditor;
}
AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
{
const ScopedLock sl (activeEditorLock);
if (activeEditor != nullptr)
return activeEditor;
@@ -820,8 +832,6 @@ AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
{
// you must give your editor comp a size before returning it..
jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
const ScopedLock sl (callbackLock);
activeEditor = ed;
}


+ 7
- 4
modules/juce_audio_processors/processors/juce_AudioProcessor.h View File

@@ -964,10 +964,13 @@ public:
virtual bool hasEditor() const = 0;
//==============================================================================
/** Returns the active editor, if there is one.
Bear in mind this can return nullptr, even if an editor has previously been opened.
/** Returns the active editor, if there is one. Bear in mind this can return nullptr
even if an editor has previously been opened.
Note that you should only call this method from the message thread as the active
editor may be deleted by the message thread, causing a dangling pointer.
*/
AudioProcessorEditor* getActiveEditor() const noexcept { return activeEditor; }
AudioProcessorEditor* getActiveEditor() const noexcept;
/** Returns the active editor, or if there isn't one, it will create one.
This may call createEditor() internally to create the component.
@@ -1465,7 +1468,7 @@ private:
int blockSize = 0, latencySamples = 0;
bool suspended = false, nonRealtime = false;
ProcessingPrecision processingPrecision = singlePrecision;
CriticalSection callbackLock, listenerLock;
CriticalSection callbackLock, listenerLock, activeEditorLock;
friend class Bus;
mutable OwnedArray<Bus> inputBuses, outputBuses;


Loading…
Cancel
Save