1
Uncaught Rangeerror: Maximum call stack size exceeded
function updateAnalysers(id) {
var canvas = document.getElementById(id);
canvasWidth = canvas.width;
canvasHeight = canvas.height;
analyserContext = canvas.getContext('2d');
{
var fils = Math.round(canvasWidth / 3);
var byts = new Uint8Array(analyserNode.frequencyBinCount);
analyserNode.getByteFrequencyData(byts);
analyserContext.clearRect(0, 0, canvasWidth, canvasHeight);
analyserContext.fillStyle = 'GRAY';
analyserContext.lineCap = 'round';
var multiplier = analyserNode.frequencyBinCount / fils;
for (var i = 0; i < fils; ++i) {
var magnitude = 0;
var offset = Math.floor( i * multiplier );
for (var j = 0; j< multiplier; j++)
magnitude += byts[offset + j];
magnitude = (magnitude / multiplier) + 2;
analyserContext.fillRect(i * 3, canvasHeight, 1, -magnitude);
}
}
rafID = window.requestAnimationFrame( updateAnalysers("analyser") );
}
Error occurs on this last line:
rafID = window.requestAnimationFrame( updateAnalysers("analyser") );
How to fix?
That function is calling itself in loop, hence the error....
– Sergio
Now, she shouldn’t be doing this, she started doing this when I put her in the "Analyser" parameter, @Sergio
– Elaine
@Sergio when I leave her just like this:
rafID = window.requestAnimationFrame( updateAnalysers );
works that is a beauty– Elaine
Try replacing rafID = window.requestAnimationFrame( updateAnalysers("Analyser") ); by rafID = window.requestAnimationFrame( updateAnalysers(id) );
– Jefferson Silva
It works because you are passing the function to be run inside the other function, when you run the function inside itself it is error.
– Sergio
@Sergio then there is no way I pass the variable?
– Elaine