【Bug】JUCE 7.0.2 AUv3 FileChooser crash (bug demo project included)

Hi dear JUCE team, I found an issue in my iOS AUv3 plugin, it has a load local file function, I’m using FileChooser and use launchAsync to open iOS native load file window, but if I open the load file window, then close plugin window from DAW, the plugin would crash, saying

pointer being freed was not allocated

happens when destruct FileChooser::Native

I prepared a juce project purely for this FileChooser function for you guys to reproduce this bug, please see the attached file.

Reproduce steps:

  1. From Xcode, debug run AUv3 in this project on a real iOS device in AUM (or any DAW supports closing plugin window)
  2. Load this AUv3, under name “iOS AUv3 FileChooser crashing bug demo”
  3. Open plugin window
  4. Click any part in this plugin (button covers the whole editor)
  5. Leave the iOS file chooser open, then close the plugin window in DAW
  6. Crash

Btw I’m using the latest develop juce version 7.0.2

I discussed with @daniel on Discord, he thinks

“The reason is not that you didn’t allocate it, but that it is owned twice…
Smart pointers (like unique_ptr or shared_ptr) own the pointee. If two such pointers (including ObjC’s own memory management) try to delete the pointee it is called a “double delete”. The system tries to delete memory that was already free, I think it is a genuine bug in JUCE”

Hope this bug can get confirmed and fixed, my plugin is getting too many 1 star review because of this :rofl:

@t0m @jules @fr810
Hey guys, help please!

We are looking into this.

Great! Thanks!!! It’s been bothering me and my users a lot :rofl:

Is this not somehow related to the fact that AUv3 plugins can no longer have child-windows (such as popup menus) because the association of the sub-window context with the main process is no longer being made (due to AUv3 sandboxing)?

I’ve seen this free error previously on our plugins, and addressed it by removing popupmenus in our GUI design, replacing them with Combo/RadioButtons instead.

But the feature I’m aiming for is let user to select his local file and import it, it better be a normal file loader for this.

And the user case which causes this bug is definitely avoid-able, I’ve checked other AUv3 plugins like Koala Sampler and FRMS, their file/preset import function does the same thing, but won’t cause crash when you close the plugin window with load window on.

They might not use JUCE, but they must used some iOS related function which JUCE can also get benefits from.

Hi, any updates on this one? Is this a confirmed bug?

We can confirm the bug. We are currently working on a fix.


Awesome!!! Thanks for the info!

Can you check that the following patch fixes your issue?

ios_filechooser_auv3_crash_fix.patch (11.8 KB)

If yes, then the fix will appear on develop in a few days once it has passed our internal code review.

Ok, do I need to copy and replace the code from JUCE? Or is there a certain way to use this patch file? Sorry for the dummy question :sweat_smile:

No problem. Ensure that you are on the latest JUCE develop. Open a terminal and navigate into the JUCE folder. Then type in:

patch -p1 < ~/PATH_TO_DOWNLOADED_PATCH_FILE_GOES_HERE/ios_filechooser_auv3_crash_fix.patch

Failed at patching, here is my command, could you help telling me where did I go wrong?

Are you sure you are on the latest develop branch? Did you do a git pull before applying the patch?

Yeah, I use Fork to manage repositories, here is my current JUCE version, fetched a few times, I think it is the latest one.

Hmmm not sure what’s going on there. It applies cleanly when I apply it to my copy of JUCE (and I’m also on 97a421f). Did you navigate to the correct JUCE folder?

In any case, here is a copy of the patched juce_ios_FileChooser.mm file. You can also just replace your copy with the file below:

juce_ios_FileChooser.mm (20.8 KB)

Hi, just pasted the .mm codes, yes it won’t crash anymore! You guys are amazing!

I do have this printed out when closing the file chooser window with Cancel button:

[DocumentManager] The view service did terminate with error: Error Domain=_UIViewServiceErrorDomain Code=1 “(null)” UserInfo={Terminated=disconnect method}

It won’t cause crash, but not sure if it is serious or not.

1 Like

The error is a harmless warning from iOS (not JUCE) that the parent view of the file chooser was removed. Nothing we can do about this as the host hides the AUv3’s editor before we can even react.

Anyways. The fix is currently in code review and I will update this thread once it’s in the public JUCE repo.

1 Like

Cool, thanks for this, I’ll be waiting for the new JUCE commit!

This is now fixed with commit b01d8c3 on the develop branch.

Please don’t use the patch I sent you above: a few major issues were found during code review (thanks @reuk) which could cause other crashes or app lock-ups.