Crash in juce::Convolution destructor

Hi,

I’m experiencing sporadic crashes of the Standalone version of my audio plugin, and they are related to the Convolution class.

My Convolution object is declared in the audioProcessor.h file:

dsp::Convolution convolverCab { dsp::Convolution::NonUniform { 512 } };

I’m loading IRs in the processBlock as suggested in the documentation. Sometimes, not always, the standalone crashes when I close it, this is the stack:

(this is the unique_ptr.h file)

I don’t have any Convolution-related code in my destructor, so the default one is called. I see that also the “Impl” destructor is called and then the same is for the “MessageQueue”. Then something related to that Queue triggers a bad access.

Is there something that I’m doing in the wrong way? I never explicitly deal with that Queue and I have just a single Convolution object.

Thank you.

[UPDATE]

I’ve switched to unique_ptr as hinted by @PaulDriessen and the problem seems solved, I’ve tried multiple times to make it happen again but it didn’t. I’ve also checked with address sanitizer as suggested by @jdv and @duvrin and everything seems ok. For the ones wondering, in CMake in order to use Asan you just have to add these lines:

add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

before juce_add_plugin.

Thank you guys!!

Are you familiar with the Address Sanitizer? Looks like it could point you to the right place.

Actually no, I’m not familiar with that but I will of course look into it, thank you.
I was mainly wondering if I was doing something wrong in the way I define that object or something else.

If you’re on Xcode go to edit scheme->Diagnostics and select the Address Sanitizer check box. This will make your build time a lot slower but that’s ok - because the sanitizer wraps every function in your code with some magic stuff. Once built, use your plugin as you normally do and wait for the sanitizer to stop you.

Don’t forget to uncheck it when you’re done with it.

I’ll check if it is possible to use that tool outside Xcode since I don’t use it. I build with Cmake and I write in Visual Studio Code.
Thank you.

You can use the sanitizer in Visual Studio 2019 and onwards. I think you just need to set the /fsanitize=address compiler flag from Cmake. See AddressSanitizer (ASan) for Windows with MSVC - C++ Team Blog.

I remember having a simular problem with Convolution, I switched to unique_ptr, but I dont know why it works better. It just does…
I’ll be following this thread to learn what’s going on here :wink:

private :
std::unique_ptr<juce::dsp::Convolution> convolverP;
 std::unique_ptr<juce::dsp::Convolution> newC( new juce::dsp::Convolution(myL)  );
 convolverP =  std::move(newC);

I’m actually on macOS, and I’m using Visual Studio Code just to write code. I’ve read that it’s pretty simple to add Asan in the CMake file, I’ll try and then update this thread for other users that may have the same problem.

This is actually one of the things that I wanted to try, I’ll give it a shot later on and update this thread!

1 Like