Emscripten: Fixed throwing JavaScript exception if no audio context available.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 14 Feb 2015 00:16:27 +0100
changeset 934483f4ab8fb0b8
parent 9343 7f58a328445c
child 9345 bf0874f4fd3a
Emscripten: Fixed throwing JavaScript exception if no audio context available.

Handling the error in C provides the possibility to just continue without audio.
src/audio/emscripten/SDL_emscriptenaudio.c
     1.1 --- a/src/audio/emscripten/SDL_emscriptenaudio.c	Sat Feb 14 00:13:00 2015 +0100
     1.2 +++ b/src/audio/emscripten/SDL_emscriptenaudio.c	Sat Feb 14 00:16:27 2015 +0100
     1.3 @@ -157,6 +157,7 @@
     1.4      SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
     1.5      int i;
     1.6      float f;
     1.7 +    int result;
     1.8  
     1.9      while ((!valid_format) && (test_format)) {
    1.10          switch (test_format) {
    1.11 @@ -185,7 +186,7 @@
    1.12      /* based on parts of library_sdl.js */
    1.13  
    1.14      /* create context (TODO: this puts stuff in the global namespace...)*/
    1.15 -    EM_ASM({
    1.16 +    result = EM_ASM_INT_V({
    1.17          if(typeof(SDL2) === 'undefined')
    1.18              SDL2 = {};
    1.19  
    1.20 @@ -198,10 +199,14 @@
    1.21              } else if (typeof(webkitAudioContext) !== 'undefined') {
    1.22                  SDL2.audioContext = new webkitAudioContext();
    1.23              } else {
    1.24 -                throw 'Web Audio API is not available!';
    1.25 +                return -1;
    1.26              }
    1.27          }
    1.28 +        return 0;
    1.29      });
    1.30 +    if (result < 0) {
    1.31 +        return SDL_SetError("Web Audio API is not available!");
    1.32 +    }
    1.33  
    1.34      /* limit to native freq */
    1.35      int sampleRate = EM_ASM_INT_V({