AudioProcessorParameter leaks - unique_ptr Incomplete Type

Hi, so in my application, I am creating a custom AudioProcessor-inherited class. I happen to be inheriting from AudioProcessorGraph::AudioGraphIOProcessor, and I get a leak upon closing the app.

In the leak, it seems that it’s because my class creates its own AudioParameterChoice, and uses the addParameter(..) method from AudioProcessor to implement it. The parameter is also added to an AudioProcessorGraph , using addParameter(), but I’m fairly sure that isn’t the root of the issue.

Anyways, I’m getting an incomplete type error. I think it may be because the unique_ptr that AudioProcessors use AudioProcessorParameter, and AudioParameterChoice, for example, would be treated as incomplete. Is this correct? How would I go about fixing an issue like this?

Here's the bottom of the stack trace, in case it clears anything up:

0x0000000000000000
std::default_deletejuce::AudioProcessorParameter::operator() unique_ptr.h:81
std::unique_ptr<juce::AudioProcessorParameter, std::default_deletejuce::AudioProcessorParameter >::~unique_ptr unique_ptr.h:284
juce::AudioProcessorParameterGroup::AudioProcessorParameterNode::~AudioProcessorParameterNode juce_AudioProcessorParameterGroup.h:60
juce::ContainerDeletePolicyjuce::AudioProcessorParameterGroup::AudioProcessorParameterNode::destroy juce_ContainerDeletePolicy.h:54
juce::OwnedArray<juce::AudioProcessorParameterGroup::AudioProcessorParameterNode, juce::DummyCriticalSection>::deleteAllObjects juce_OwnedArray.h:863
juce::OwnedArray<juce::AudioProcessorParameterGroup::AudioProcessorParameterNode, juce::DummyCriticalSection>::~OwnedArray juce_OwnedArray.h:64
juce::AudioProcessorParameterGroup::~AudioProcessorParameterGroup juce_AudioProcessorParameterGroup.h:42
juce::AudioProcessor::~AudioProcessor juce_AudioProcessor.cpp:53
juce::AudioPluginInstance::~AudioPluginInstance juce_AudioPluginInstance.h:62
juce::AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor juce_AudioProcessorGraph.cpp:1373

This seems to be the problem. You can add a parameter to only one AudioProcessor. The documentation for addParameter() says:

The parameter object will be managed and deleted automatically by the AudioProcessor when no longer needed.

By calling addParameter() twice with the same parameter, there are now two AudioProcessors that try to delete the parameter when the app shuts down. The first one succeeds, and the second one crashes.

I think AudioProcessor::addParameter should be changed to take a unique_ptr to prevent this from happening.

1 Like