From 6c148825813a175afaa1e7d278734a1ef08613f4 Mon Sep 17 00:00:00 2001 From: Divyanshu Raj Date: Wed, 17 Mar 2021 13:17:22 +0530 Subject: [PATCH 1/2] fixed repeated initilisation of audioWorklet --- src/audioWorklet/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/audioWorklet/index.js b/src/audioWorklet/index.js index eae80bfe..b930d5c7 100644 --- a/src/audioWorklet/index.js +++ b/src/audioWorklet/index.js @@ -17,6 +17,7 @@ function loadAudioWorkletModules() { } p5.prototype.registerMethod('init', function () { + if (initializedAudioWorklets) return; // ensure that a preload function exists so that p5 will wait for preloads to finish if (!this.preload && !window.preload) { this.preload = function () {}; From 0091905265a60ad8cac70f751cc4aafe696544c6 Mon Sep 17 00:00:00 2001 From: Divyanshu Raj Date: Wed, 17 Mar 2021 14:20:39 +0530 Subject: [PATCH 2/2] fixed some mistakes --- src/audioWorklet/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/audioWorklet/index.js b/src/audioWorklet/index.js index b930d5c7..6180b7a4 100644 --- a/src/audioWorklet/index.js +++ b/src/audioWorklet/index.js @@ -5,6 +5,7 @@ const moduleSources = [ require('raw-loader!./amplitudeProcessor').default, ]; const ac = p5sound.audiocontext; +let initializedAudioWorklets = false; function loadAudioWorkletModules() { return Promise.all( @@ -26,6 +27,7 @@ p5.prototype.registerMethod('init', function () { // use p5's preload system to load necessary AudioWorklet modules before setup() this._incrementPreload(); const onWorkletModulesLoad = function () { + initializedAudioWorklets = true; this._decrementPreload(); }.bind(this); loadAudioWorkletModules().then(onWorkletModulesLoad);