Преглед на файлове

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

j8
Lyubomir Marinov преди 11 години
родител
ревизия
e9a3b45316
променени са 2 файла, в които са добавени 25 реда и са изтрити 5 реда
  1. 16
    4
      audio_levels.js
  2. 9
    1
      canvas_util.js

+ 16
- 4
audio_levels.js Целия файл

@@ -117,15 +117,27 @@ var AudioLevels = (function(my) {
117 117
 
118 118
             var audioLevelCanvasOrig = $('#' + videoSpanId + '>canvas').get(0);
119 119
 
120
-            audioLevelCanvasCache[resourceJid]
121
-                = CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
120
+            /*
121
+             * FIXME Testing has shown that audioLevelCanvasOrig may not exist.
122
+             * In such a case, the method CanvasUtil.cloneCanvas may throw an
123
+             * error. Since audio levels are frequently updated, the errors have
124
+             * been observed to pile into the console, strain the CPU.
125
+             */
126
+            if (audioLevelCanvasOrig)
127
+            {
128
+                audioLevelCanvasCache[resourceJid]
129
+                    = CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
130
+            }
122 131
         }
123 132
 
124 133
         var canvas = audioLevelCanvasCache[resourceJid];
125 134
 
135
+        if (!canvas)
136
+            return;
137
+
126 138
         var drawContext = canvas.getContext('2d');
127 139
 
128
-        drawContext.clearRect (0, 0, canvas.width, canvas.height);
140
+        drawContext.clearRect(0, 0, canvas.width, canvas.height);
129 141
 
130 142
         var shadowLevel = getShadowLevel(audioLevel);
131 143
 
@@ -190,4 +202,4 @@ var AudioLevels = (function(my) {
190 202
 
191 203
     return my;
192 204
 
193
-})(AudioLevels || {});
205
+})(AudioLevels || {});

+ 9
- 1
canvas_util.js Целия файл

@@ -81,6 +81,14 @@ var CanvasUtil = (function(my) {
81 81
      * @return the new cloned canvas.
82 82
      */
83 83
     my.cloneCanvas = function (oldCanvas) {
84
+        /*
85
+         * FIXME Testing has shown that oldCanvas may not exist. In such a case,
86
+         * the method CanvasUtil.cloneCanvas may throw an error. Since audio
87
+         * levels are frequently updated, the errors have been observed to pile
88
+         * into the console, strain the CPU.
89
+         */
90
+        if (!oldCanvas)
91
+            return oldCanvas;
84 92
 
85 93
         //create a new canvas
86 94
         var newCanvas = document.createElement('canvas');
@@ -98,4 +106,4 @@ var CanvasUtil = (function(my) {
98 106
     };
99 107
 
100 108
     return my;
101
-})(CanvasUtil || {});
109
+})(CanvasUtil || {});

Loading…
Отказ
Запис