diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 10:57:59 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 10:57:59 -0700 |
commit | a04d065e40adbca5694c608331e137a6280795bd (patch) | |
tree | 49834ea2334f40e478d7274d8f965e434464d883 /src | |
parent | 637ad69e97761fde5ec5dee882b14f3bb49f561e (diff) | |
parent | 7eaba0c3322cd5e44200bedcd070e6d149f413cd (diff) |
Merge pull request #1317 from michaeljbishop/sdl-mixer-sound-leak
SDL mixer sound leak
Diffstat (limited to 'src')
-rw-r--r-- | src/library_sdl.js | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 356c9746..176a2fae 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1385,26 +1385,28 @@ var LibrarySDL = { // If the user asks us to allocate a channel automatically, get the first // free one. if (channel == -1) { - channel = SDL.channelMinimumNumber; for (var i = SDL.channelMinimumNumber; i < SDL.numChannels; i++) { if (!SDL.channels[i].audio) { channel = i; break; } } + if (channel == -1) { + Module.printErr('All ' + SDL.numChannels + ' channels in use!'); + return -1; + } } - // We clone the audio node to utilize the preloaded audio buffer, since // the browser has already preloaded the audio file. var channelInfo = SDL.channels[channel]; channelInfo.audio = audio = audio.cloneNode(true); audio.numChannels = info.audio.numChannels; audio.frequency = info.audio.frequency; - // TODO: handle N loops. Behavior matches Mix_PlayMusic audio.loop = loops != 0; - if (SDL.channelFinished) { - audio['onended'] = function() { // TODO: cache these + audio['onended'] = function() { // TODO: cache these + channelInfo.audio = null; + if (SDL.channelFinished) { Runtime.getFuncWrapper(SDL.channelFinished, 'vi')(channel); } } @@ -1461,7 +1463,6 @@ var LibrarySDL = { audio.play(); } audio.volume = channelInfo.volume; - audio.paused = false; return channel; }, Mix_PlayChannelTimed: 'Mix_PlayChannel', // XXX ignore Timing @@ -1475,6 +1476,8 @@ var LibrarySDL = { if (info.audio) { info.audio.pause(); info.audio = null; + } else { + Module.printErr('No Audio for channel: ' + channel); } if (SDL.channelFinished) { Runtime.getFuncWrapper(SDL.channelFinished, 'vi')(channel); @@ -1512,6 +1515,12 @@ var LibrarySDL = { } audio.volume = SDL.music.volume; audio['onended'] = _Mix_HaltMusic; // will send callback + if (SDL.music.audio) { + if (!SDL.music.audio.paused) { + Module.printErr('Music is already playing. ' + SDL.music.source); + } + SDL.music.audio.pause(); + } SDL.music.audio = audio; return 0; }, @@ -1577,7 +1586,8 @@ var LibrarySDL = { var info = SDL.channels[channel]; if (info && info.audio) { info.audio.pause(); - info.audio.paused = true; + } else { + Module.printErr('Mix_Pause: no sound found for channel: ' + channel); } }, |