我使用glfx.js在画布上添加了一些效果。我创建了一个更改画布的按钮,有时会收到错误“错误:未捕获的异常:编译错误:”。感谢JavaScript global error handling。我得到了更多详细信息。
我将window.onerror事件分配给事件处理程序,我得到了:
错误:未捕获的异常:编译错误: 网址: 行:0
错误:编译错误:
我该如何解决该错误?
代码:
function createContrastCanvas( imgEffect, canvasSent, p, A, x ) {
$( ".loaderImgEffects" ).fadeIn();
var base64 = canvasSent.toDataURL( "image/jpeg" );
var image = new Image();
image.setAttribute( "id", "contrast_image");
image.addEventListener( "load", function() {
console.log(2);
document.body.appendChild( image );
try {
var canvas = fx.canvas();
canvas.setAttribute( "id", "dialog_canvas" );
console.log(3);
} catch (e) {
alert(e);
return;
}
// convert the image to a texture
var contrastImage = document.getElementById( 'contrast_image' );
var texture = canvas.texture( contrastImage );
console.log( 4 );
switch( imgEffect ) {
case "contrast":
console.log(5);
canvas.draw(texture).brightnessContrast(0.1, 0.24).update();
//contrastBase64[0] = canvas.toDataURL( "image/jpeg" );
contrastBase64[0] = image;
break;
case "hue":
console.log(5);
canvas.draw(texture).hueSaturation( 0, 0.39 ).update();
//hueBase64[0] = canvas.toDataURL( "image/jpeg" );
hueBase64[0] = image;
break;
/*case "denoise":
canvas.draw(texture).unsharpMask(20, 0.45).update();
break;*/
}
console.log(6);
// replace the image with the canvas
$( "#dialog_canvas" ).parent().html( canvas );
$( ".loaderImgEffects" ).fadeOut();
//activeAllEvents( canvas, p, A, x );
//document.getElementById( "dialog_canvas" ).parentNode.removeChild( contrastImage );
} )
image.src = base64;
}