From fc9e521a853d5e933681756b99c5245ca6b7a8cc Mon Sep 17 00:00:00 2001
From: Robbert van der Helm <mail@robbertvanderhelm.nl>
Date: Fri, 4 Nov 2022 15:00:45 +0100
Subject: [PATCH] Fix potential VST3 parking_lot allocation failure

This can happen when the process function is called from a new thread or
when a new thread has been spawned.
---
 src/wrapper/vst3/wrapper.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs
index fc6b7225..7cb147cf 100644
--- a/src/wrapper/vst3/wrapper.rs
+++ b/src/wrapper/vst3/wrapper.rs
@@ -1561,7 +1561,9 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
                 }
 
                 let result = if buffer_is_valid {
-                    let mut plugin = self.inner.plugin.lock();
+                    // NOTE: `parking_lot`'s mutexes sometimes allocate because of their use of
+                    //       thread locals
+                    let mut plugin = permit_alloc(|| self.inner.plugin.lock());
                     // SAFETY: Shortening these borrows is safe as even if the plugin overwrites the
                     //         slices (which it cannot do without using unsafe code), then they
                     //         would still be reset on the next iteration