mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fixed a mistake that made AudioPluginFormat::createPluginInstanceAsync() do its callback synchronously, and also made it survive a situation where the format object is deleted before the callback
This commit is contained in:
parent
01935e3338
commit
63e31a9fea
2 changed files with 26 additions and 33 deletions
|
|
@ -27,7 +27,7 @@
|
|||
namespace juce
|
||||
{
|
||||
|
||||
AudioPluginFormat::AudioPluginFormat() noexcept {}
|
||||
AudioPluginFormat::AudioPluginFormat() {}
|
||||
AudioPluginFormat::~AudioPluginFormat() {}
|
||||
|
||||
std::unique_ptr<AudioPluginInstance> AudioPluginFormat::createInstanceFromDescription (const PluginDescription& desc,
|
||||
|
|
@ -69,41 +69,31 @@ std::unique_ptr<AudioPluginInstance> AudioPluginFormat::createInstanceFromDescri
|
|||
return instance;
|
||||
}
|
||||
|
||||
struct AudioPluginFormat::AsyncCreateMessage : public Message
|
||||
{
|
||||
AsyncCreateMessage (const PluginDescription& d, double sr, int size, PluginCreationCallback call)
|
||||
: desc (d), sampleRate (sr), bufferSize (size), callbackToUse (std::move (call))
|
||||
{
|
||||
}
|
||||
|
||||
PluginDescription desc;
|
||||
double sampleRate;
|
||||
int bufferSize;
|
||||
PluginCreationCallback callbackToUse;
|
||||
};
|
||||
|
||||
void AudioPluginFormat::createPluginInstanceAsync (const PluginDescription& description,
|
||||
double initialSampleRate, int initialBufferSize,
|
||||
PluginCreationCallback callback)
|
||||
{
|
||||
jassert (callback != nullptr);
|
||||
postMessage (new AsyncCreateMessage (description, initialSampleRate, initialBufferSize, std::move (callback)));
|
||||
}
|
||||
|
||||
if (MessageManager::getInstance()->isThisTheMessageThread())
|
||||
{
|
||||
createPluginInstance (description, initialSampleRate, initialBufferSize, std::move (callback));
|
||||
return;
|
||||
}
|
||||
|
||||
struct InvokeOnMessageThread : public CallbackMessage
|
||||
{
|
||||
InvokeOnMessageThread (AudioPluginFormat& f, const PluginDescription& d,
|
||||
double sr, int size, PluginCreationCallback call)
|
||||
: format (f), desc (d), sampleRate (sr), bufferSize (size),
|
||||
callbackToUse (std::move (call))
|
||||
{
|
||||
post();
|
||||
}
|
||||
|
||||
void messageCallback() override
|
||||
{
|
||||
format.createPluginInstance (desc, sampleRate, bufferSize, std::move (callbackToUse));
|
||||
}
|
||||
|
||||
AudioPluginFormat& format;
|
||||
PluginDescription desc;
|
||||
double sampleRate;
|
||||
int bufferSize;
|
||||
PluginCreationCallback callbackToUse;
|
||||
};
|
||||
|
||||
new InvokeOnMessageThread (*this, description, initialSampleRate, initialBufferSize, std::move (callback));
|
||||
void AudioPluginFormat::handleMessage (const Message& message)
|
||||
{
|
||||
if (auto m = dynamic_cast<const AsyncCreateMessage*> (&message))
|
||||
createPluginInstance (m->desc, m->sampleRate, m->bufferSize, std::move (m->callbackToUse));
|
||||
}
|
||||
|
||||
} // namespace juce
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ namespace juce
|
|||
|
||||
@tags{Audio}
|
||||
*/
|
||||
class JUCE_API AudioPluginFormat
|
||||
class JUCE_API AudioPluginFormat : private MessageListener
|
||||
{
|
||||
public:
|
||||
/** Destructor. */
|
||||
virtual ~AudioPluginFormat();
|
||||
~AudioPluginFormat() override;
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the format name.
|
||||
|
|
@ -136,7 +136,7 @@ protected:
|
|||
//==============================================================================
|
||||
friend class AudioPluginFormatManager;
|
||||
|
||||
AudioPluginFormat() noexcept;
|
||||
AudioPluginFormat();
|
||||
|
||||
/** Implementors must override this function. This is guaranteed to be called on
|
||||
the message thread. You may call the callback on any thread.
|
||||
|
|
@ -147,6 +147,9 @@ protected:
|
|||
virtual bool requiresUnblockedMessageThreadDuringCreation (const PluginDescription&) const noexcept = 0;
|
||||
|
||||
private:
|
||||
struct AsyncCreateMessage;
|
||||
void handleMessage (const Message&) override;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioPluginFormat)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue