Have you tested any of the JUCE demos that include a Convolution (ConvolutionDemo, DSPModulePluginDemo)? You could try modifying the ConvolutionDemo to load your impulse responses and check whether it still crashes. If not, then the problem is probably not in the Convolution itself.
Hi, thanks for the reply. I just tried with my files in the JUCE demo, it works great, and I have narrowed the bug to be a EXC_BAD_ACCESS somewhere in Convolution::Mixer::processBlock, seems it’s allocating some released data.
The only difference between my code and the demo that I can analyze might be the IR reading source, in demo it’s reading from demo project included asset, but my user case is reading from user’s local file, does that mean I have to save the previous file entirely into maybe a daw project memory data like APVTS for the smooth IR switching?
If the problem isn’t present in the ConvolutionDemo, then the issue is probably due to some aspect of your particular project.
A handy tool for tracking down segfaults is Address Sanitizer. You can enable this in Xcode by going to the target drop-down at the top of the window, clicking “edit scheme”, and then enabling Address Sanitizer from the “Diagnostics” tab. Then, when your application reads or writes to an address that is invalid for some reason, it will print some helpful information to the console explaining the problem.
My method is loading a local file into a reader then use exactly how JUCE demo apples it to the buffer in processBlock, crash after switching IR files a few times. And I also tried loading from local file method like this demo from viatordsp, and his demo also crashes on IR switching (you can download his project and try).
The main difference I can tell is JUCE demo is using IR files which comes from builtin asset, not local dragged file, which might have something wrong with how Convolution deals with new IR file loading.
And I also checked the JUCE Document, but it didn’t say anything special for loadImpulseResponse() from local files.
Calling loadImpulseResponse from one thread while another thread is calling process is not supported. This is explained in the documentation for the Convolution class:
I expect that your program has the same problem. Please take another look at the ConvolutionDemo for an approach to loading impulse response files from the main thread and communicating them to the audio thread.