yung-hans
yung-hans

Reputation: 57

multiple OfflineAudioContext crashing browser

I have an array of about 60 audio files, (~3min each). I loop through this array - for each item I create an OfflineAudioContext and then do some filtering and processing like so:

var request = new XMLHttpRequest();
request.open('GET', audioFile.source, true);
request.responseType = "arraybuffer";

request.onload = function(){

    context.decodeAudioData(request.response, function(buffer) {

        audioFileBuffer = buffer;  

        offlineContext = new OfflineAudioContext(1, buffer.length, buffer.sampleRate);

        //do some processing

        //do some checks

    }

}

Even without any processing or 'checks' this will cause the browser to crash at around the 30 mark. I've tried going through the array slowly (button clicks for each item) but the browser will still crash around this threshold.

After the processing & checks are complete the offlineContext and anything used to create it are no longer needed - is this still taking up memory somewhere and causing the browser to crash?

EDIT: changed the code to test more specific areas and it appears that offline audio context will crash only chrome, the following test will complete all 1000 runs in opera, ff & safari but will crash at ~170 in chrome.

for(i=0; i<1000; i++){
    var off = new webkitOfflineAudioContext(1, 1764000, 44100);
    console.log(i);
}

Chrome gives the error: "Uncaught NotSupportedError: Failed to construct 'OfflineAudioContext': OfflineAudioContext(1, 1764000, 44100)" and then will crash if the page is refreshed

Upvotes: 1

Views: 356

Answers (2)

dansch
dansch

Reputation: 6267

OfflineAudioContext was crashing my page when I accidentally created one that was 24 times too long.

I think if you create too many, or create one that is too long, it will immediately crash because it doesn't have enough memory.

Try garbage collecting, or perhaps doing them one at a time in sequence.

Upvotes: 0

cwilso
cwilso

Reputation: 13908

Without seeing all the surrounding code, I can't tell. Can you remove the decodeAudioData calls and just create 30+ OfflineAudioContexts of the given lengths and see if it has the same issues? (i.e. don't load the buffers).

Upvotes: 3

Related Questions