Skip to content

Commit bee6e4a

Browse files
authored
Canvas.getImageData error defense (#2508)
1 parent 621b9ff commit bee6e4a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/maptalks/src/renderer/geometry/Painter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,11 +751,15 @@ class Painter extends Class {
751751
Canvas.setHitTesting(false);
752752
}
753753
delete this._hitPoint;
754-
const imgData = ctx.getImageData(0, 0, testCanvas.width, testCanvas.height).data;
755-
for (let i = 3, l = imgData.length; i < l; i += 4) {
756-
if (imgData[i] > 0) {
757-
return true;
754+
try {
755+
const imgData = ctx.getImageData(0, 0, testCanvas.width, testCanvas.height).data;
756+
for (let i = 3, l = imgData.length; i < l; i += 4) {
757+
if (imgData[i] > 0) {
758+
return true;
759+
}
758760
}
761+
} catch (error) {
762+
console.error(error);
759763
}
760764
return false;
761765
}

0 commit comments

Comments
 (0)