Browse Source

[HTML5] Catch audio worklet errors on disconnect.

Which could happen if the worklet was not fully loaded, or the audio
context had already aborted.
Fabio Alessandrelli 4 years ago
parent
commit
0816011e86
1 changed files with 4 additions and 1 deletions
  1. 4 1
      platform/javascript/js/libs/library_godot_audio.js

+ 4 - 1
platform/javascript/js/libs/library_godot_audio.js

@@ -238,6 +238,9 @@ const GodotAudioWorklet = {
 
 		close: function () {
 			return new Promise(function (resolve, reject) {
+				if (GodotAudioWorklet.promise === null) {
+					return;
+				}
 				GodotAudioWorklet.promise.then(function () {
 					GodotAudioWorklet.worklet.port.postMessage({
 						'cmd': 'stop',
@@ -247,7 +250,7 @@ const GodotAudioWorklet = {
 					GodotAudioWorklet.worklet = null;
 					GodotAudioWorklet.promise = null;
 					resolve();
-				});
+				}).catch(function (err) { /* aborted? */ });
 			});
 		},
 	},