emscripten: Be more aggressive when closing audio capture devices.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 31 Aug 2016 16:10:04 -0400
changeset 10301a25d9c643cfb
parent 10300 c5300ace12f2
child 10302 729eff9ee77a
emscripten: Be more aggressive when closing audio capture devices.

Fixes exceptions being thrown on shutdown.
src/audio/emscripten/SDL_emscriptenaudio.c
     1.1 --- a/src/audio/emscripten/SDL_emscriptenaudio.c	Wed Aug 31 12:52:55 2016 -0400
     1.2 +++ b/src/audio/emscripten/SDL_emscriptenaudio.c	Wed Aug 31 16:10:04 2016 -0400
     1.3 @@ -203,7 +203,15 @@
     1.4              if (SDL2.capture.silenceTimer !== undefined) {
     1.5                  clearTimeout(SDL2.capture.silenceTimer);
     1.6              }
     1.7 +            if (SDL2.capture.stream !== undefined) {
     1.8 +                var tracks = SDL2.capture.stream.getAudioTracks();
     1.9 +                for (var i = 0; i < tracks.length; i++) {
    1.10 +                    SDL2.capture.stream.removeTrack(tracks[i]);
    1.11 +                }
    1.12 +                SDL2.capture.stream = undefined;
    1.13 +            }
    1.14              if (SDL2.capture.scriptProcessorNode !== undefined) {
    1.15 +                SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {};
    1.16                  SDL2.capture.scriptProcessorNode.disconnect();
    1.17                  SDL2.capture.scriptProcessorNode = undefined;
    1.18              }
    1.19 @@ -344,6 +352,7 @@
    1.20                  };
    1.21                  SDL2.capture.mediaStreamNode.connect(SDL2.capture.scriptProcessorNode);
    1.22                  SDL2.capture.scriptProcessorNode.connect(SDL2.audioContext.destination);
    1.23 +                SDL2.capture.stream = stream;
    1.24              };
    1.25  
    1.26              var no_microphone = function(error) {