From 8ac4b81477e7a2e086ecfde19b6a9691ffca2d8b Mon Sep 17 00:00:00 2001 From: William Toohey Date: Sun, 6 Mar 2016 01:54:17 +1000 Subject: [PATCH] Fix race condition on song load --- src/js/SoundManager.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/SoundManager.js b/src/js/SoundManager.js index 2c318b6..95c66fa 100644 --- a/src/js/SoundManager.js +++ b/src/js/SoundManager.js @@ -285,9 +285,11 @@ SoundManager.prototype.clampedTime = function() { SoundManager.prototype.loadSong = function(song) { if(song._loadPromise) { - // Someone went forward then immediately back then forward again - // Either way, the sound is still loading. It'll come back when it's ready - return song._loadPromise; + /* Caused when moving back/forwards rapidly. + The sound is still loading. We reject this promise, and the already + running decode will finish and resolve instead. + NOTE: If anything but playSong calls loadSong, this idea is broken. */ + return Promise.reject("Song changed between load and play - this message can be ignored"); } let buffers = {loop: null, buildup: null};