Fixes an error caused by trying to get a property of undefined related to audio levels.

pull/93/head
Lyubomir Marinov 11 years ago
parent 05975e30a3
commit e9a3b45316
  1. 20
      audio_levels.js
  2. 10
      canvas_util.js

@ -117,15 +117,27 @@ var AudioLevels = (function(my) {
var audioLevelCanvasOrig = $('#' + videoSpanId + '>canvas').get(0);
audioLevelCanvasCache[resourceJid]
= CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
/*
* FIXME Testing has shown that audioLevelCanvasOrig may not exist.
* In such a case, the method CanvasUtil.cloneCanvas may throw an
* error. Since audio levels are frequently updated, the errors have
* been observed to pile into the console, strain the CPU.
*/
if (audioLevelCanvasOrig)
{
audioLevelCanvasCache[resourceJid]
= CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
}
}
var canvas = audioLevelCanvasCache[resourceJid];
if (!canvas)
return;
var drawContext = canvas.getContext('2d');
drawContext.clearRect (0, 0, canvas.width, canvas.height);
drawContext.clearRect(0, 0, canvas.width, canvas.height);
var shadowLevel = getShadowLevel(audioLevel);
@ -190,4 +202,4 @@ var AudioLevels = (function(my) {
return my;
})(AudioLevels || {});
})(AudioLevels || {});

@ -81,6 +81,14 @@ var CanvasUtil = (function(my) {
* @return the new cloned canvas.
*/
my.cloneCanvas = function (oldCanvas) {
/*
* FIXME Testing has shown that oldCanvas may not exist. In such a case,
* the method CanvasUtil.cloneCanvas may throw an error. Since audio
* levels are frequently updated, the errors have been observed to pile
* into the console, strain the CPU.
*/
if (!oldCanvas)
return oldCanvas;
//create a new canvas
var newCanvas = document.createElement('canvas');
@ -98,4 +106,4 @@ var CanvasUtil = (function(my) {
};
return my;
})(CanvasUtil || {});
})(CanvasUtil || {});

Loading…
Cancel
Save