From 773c167987258a098ddc938949ff66ce17d98468 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 28 Nov 2017 13:15:48 -0500 Subject: [PATCH] Check for instrument sample before playing --- src/extensions/scratch3_music/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/extensions/scratch3_music/index.js b/src/extensions/scratch3_music/index.js index e170cf396..807c3f792 100644 --- a/src/extensions/scratch3_music/index.js +++ b/src/extensions/scratch3_music/index.js @@ -602,6 +602,10 @@ class Scratch3MusicBlocks { const sampleArray = instrumentInfo.samples; const sampleIndex = this._selectSampleIndexForNote(note, sampleArray); + // If the audio sample has not loaded yet, bail out + if (typeof this._instrumentBufferArrays[inst] === 'undefined') return; + if (typeof this._instrumentBufferArrays[inst][sampleIndex] === 'undefined') return; + // Create the audio buffer to play the note, and set its pitch const context = util.runtime.audioEngine.audioContext; const bufferSource = context.createBufferSource();