admin管理员组文章数量:1425868
Sometimes I some errors like this one when I'm working with canvas on Firefox:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMCanvasRenderingContext2D.lineWidth]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: media/js/canvas/Rectangle.js :: :: line 34" data: no]
It happens when i'm working with more than 5 canvas elements, on a for loop. The function what creates them is this:
function addCanvas(id) {
var canvas = document.getElementById(id);
if (canvas == null) {
$('#content').append(
'<canvas id="' + id + '" width="' + workAreaWidth +'" height="'
+ workAreaHeight + '"></canvas>'
);
canvas = document.getElementById(id).getContext('2d');
} else {
canvas = canvas.getContext('2d');
canvas.setTransform(1, 0, 0, 1, 0, 0);
canvas.clearRect(0, 0, workAreaWidth, workAreaHeight);
}
return canvas;
}
The for loop is in another function.
What happens is that not all the canvas elements are updated. I guess cause of the exception.
I can't post the code of the place where it exactly fails, cause it fails randomly in many places, always with the same error.
The Firefox version is 9.0, but also happened on 8.0.1. I didn't test it on previous releases. My operating system is Mac Snow Leopard. I guess it will help. It doesn't fail on Chrome or Safari,
Thanks for your help.
Sometimes I some errors like this one when I'm working with canvas on Firefox:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMCanvasRenderingContext2D.lineWidth]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: media/js/canvas/Rectangle.js :: :: line 34" data: no]
It happens when i'm working with more than 5 canvas elements, on a for loop. The function what creates them is this:
function addCanvas(id) {
var canvas = document.getElementById(id);
if (canvas == null) {
$('#content').append(
'<canvas id="' + id + '" width="' + workAreaWidth +'" height="'
+ workAreaHeight + '"></canvas>'
);
canvas = document.getElementById(id).getContext('2d');
} else {
canvas = canvas.getContext('2d');
canvas.setTransform(1, 0, 0, 1, 0, 0);
canvas.clearRect(0, 0, workAreaWidth, workAreaHeight);
}
return canvas;
}
The for loop is in another function.
What happens is that not all the canvas elements are updated. I guess cause of the exception.
I can't post the code of the place where it exactly fails, cause it fails randomly in many places, always with the same error.
The Firefox version is 9.0, but also happened on 8.0.1. I didn't test it on previous releases. My operating system is Mac Snow Leopard. I guess it will help. It doesn't fail on Chrome or Safari,
Thanks for your help.
Share Improve this question edited Dec 28, 2011 at 21:09 elxordi asked Dec 28, 2011 at 20:25 elxordielxordi 4863 silver badges11 bronze badges 2- What is a 'for bucle'? (Did you mean 'for loop'?) – zwol Commented Dec 28, 2011 at 20:55
- Yeah, sorry... i'm not english. Ill edit the post to correct it. – elxordi Commented Dec 28, 2011 at 21:08
1 Answer
Reset to default 6These error messages are confusing to the uninitiated, but there's a lot of information packed into them. The important parts are:
Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMCanvasRenderingContext2D.lineWidth]
Ignore the hexadecimal number: this is telling you that the accessor nsIDOMRenderingContext2D.lineWidth
returned a generic failure code (NS_ERROR_FAILURE
) rather than a line width. nsIDOMRenderingContext2D
is the internal name of the C++ class that implements the object you get back from getContext("2d")
on a canvas element.
location: "JS frame :: media/js/canvas/Rectangle.js :: :: line 34"
The call from JavaScript into the C++ method that failed is at line 34 of media/js/canvas/Rectangle.js
. That's your code. That is not, however, the code that you quoted, but maybe we can figure out what's wrong by looking at the code for the accessor that failed: http://mxr.mozilla/mozilla-central/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#3180
nsresult
nsCanvasRenderingContext2D::GetLineWidth(float *width)
{
if (!EnsureSurface())
return NS_ERROR_FAILURE;
gfxFloat d = mThebes->CurrentLineWidth();
*width = static_cast<float>(d);
return NS_OK;
}
Okay, so the only way that can fail is if EnsureSurface
fails. That is defined at http://mxr.mozilla/mozilla-central/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#1154 and I'm not going to quote it here because it's huge and has a whole bunch of ways it can fail. However, it looks to me like one of your canvas elements is either not properly defined, or is not being given a chance to initialize itself (i.e. you need to allow the event loop to run).
EDIT: Concrete advice: Change the function you quoted to be like this:
function addCanvas(id, continuation) {
if (document.getElementById(id) === null) {
$('#content').append(
'<canvas id="' + id + '" width="' + workAreaWidth +'" height="'
+ workAreaHeight + '"></canvas>'
);
}
setTimeout(function() {
var canvas = document.getElementById(id).getContext('2d');
canvas.setTransform(1, 0, 0, 1, 0, 0);
canvas.clearRect(0, 0, workAreaWidth, workAreaHeight);
continuation(canvas);
}, 0);
}
You'll also need to change all callers to match. I do not guarantee that this will work, but it's the most plausible thing I can think of.
本文标签: javascriptFirefox throws error 0x80004005 when working with canvasStack Overflow
版权声明:本文标题:javascript - Firefox throws error 0x80004005 when working with canvas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745459277a2659247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论