Skip to content

Commit 3de34ec

Browse files
committed
patch audioWorklet.addModule instance mode
When p5 runs in "instance mode" it can re-run preload multiple times, and will attempt to re-register the same AudioWorklet modules multiple times. This throws an error, but we can catch and return the promise anyway since the module has already been loaded.
1 parent c02bc88 commit 3de34ec

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/audioWorklet/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ function loadAudioWorkletModules() {
1010
return Promise.all(moduleSources.map(function(moduleSrc) {
1111
const blob = new Blob([moduleSrc], { type: 'application/javascript' });
1212
const objectURL = URL.createObjectURL(blob);
13-
return ac.audioWorklet.addModule(objectURL);
13+
return ac.audioWorklet
14+
.addModule(objectURL)
15+
// in "p5 instance mode," the module may already be registered
16+
.catch(() => Promise.resolve());
1417
}));
1518
}
1619

0 commit comments

Comments
 (0)