Javascript 组件返回失败代码:0x80040111 (NS_ERROR_NOT_AVAILABLE)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6847713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE)
提问by Clement Bellot
My problem :
我的问题 :
uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMCanvasRenderingContext2D.drawImage]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: file:///***************.js :: redrawView :: line 308" data: no]
The code which produce this behaviour (tmpImg is loading dynamically, so if it is not loaded yet, it skip it).
产生此行为的代码(tmpImg 正在动态加载,因此如果尚未加载,则跳过它)。
if(tmpImg!=null && tmpImg.img.complete===true && tmpImg.img.src!=null){
var tmpPos = i_getCoordsImage(tmpImg);
var rect = getRectInCurrentView(tmpPos.x,tmpPos.y,tmpPos.w,tmpPos.h);
console.log(tmpImg);
console.log(rect);
mainDisplayContext.drawImage(tmpImg.img,rect.x,rect.y,rect.w,rect.h);
}
The problem happens several times when the tmpImg is just loaded (a least according to Firebug's log), and then disappear.
The code snippet is called several times in a row, so I can't see if the image is actually displayed when the error is thrown.
The value in rect.* are floating point, something like {x:-1500, y:-2500,h:1000,w:1000}
当 tmpImg 刚刚加载(至少根据 Firebug 的日志)时,问题会发生多次,然后消失。
代码片段连续调用了好几次,所以在抛出错误的时候看不到图片是否真的显示出来了。
rect.* 中的值是浮点数,类似于 {x:-1500, y:-2500,h:1000,w:1000}
Do you have any idea about the origin of this error ?
你知道这个错误的起源吗?
Edit 1
编辑 1
This code produce the error (you need to have an image named "test.png" in the same directory
此代码产生错误(您需要在同一目录中有一个名为“test.png”的图像
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta charset="UTF-8" />
</head>
<body id="body">
<canvas id="canvas" width="600" height="600"></canvas>
<script>
//[CDATA[
var img = new Image();
var mdc = document.getElementById("canvas").getContext("2d");
function displayCallback(){
if(img.complete===true && img.src!=null){
mdc.drawImage(img,0,0,600,600);
}
setTimeout(displayCallback, 50);
}
setTimeout(function(){img.src = "test.png";}, 10000);
setTimeout(displayCallback, 1000);
//]]
</script>
</body>
</html>
It seems related to the fact that the empty image has a src propriety of "". Is it always true ?
这似乎与空图像的 src 属性为“”有关。它总是真的吗?
edit 2
编辑 2
In fact, for the bug reporting, this JavaScript would suffice (if I understood) :
事实上,对于错误报告,这个 JavaScript 就足够了(如果我理解的话):
document.getElementById("canvas").getContext("2d").drawImage(new Image(),0,0);
回答by zwol
You get this kind of unhelpful error message from Firefox when a DOM API call throws a Javascript exception that isn't caught. The code implementing drawImage -- http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#3212-- appears to return the error code NS_ERROR_NOT_AVAILABLE (which is translated to a JS exception at the C++/JS boundary) when, for some reason, all of the data it needs to draw the image is not currently available. It appears that this can happen even when the image is considered to be fully loaded; I am not familiar enough with this part of the code to know why that might be.
当 DOM API 调用抛出未捕获的 Javascript 异常时,您会从 Firefox 收到这种无用的错误消息。该代码实现的drawImage - http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#3212-似乎返回错误代码NS_ERROR_NOT_AVAILABLE(这是转换为JS异常在 C++/JS 边界)时,由于某种原因,绘制图像所需的所有数据当前都不可用。即使图像被认为是完全加载的,这似乎也可能发生;我对这部分代码不够熟悉,不知道为什么会这样。
It is my opinion as an occasional Firefox internals hacker that you have found a bug in the browser: the specification for drawImagedoes not license the production of an exception with this error code under any circumstances. (Note the comment on line 3243, which seems to have misunderstood what the spec says.) Please construct a complete, self-contained test case that demonstrates the problem, and I will then be happy to help you file a bug report.
作为偶尔的 Firefox 内部黑客,我认为您在浏览器中发现了一个错误:drawImage的规范不允许在任何情况下产生带有此错误代码的异常。(注意第 3243 行的注释,它似乎误解了规范的内容。)请构建一个完整的、自包含的测试用例来演示问题,然后我将很乐意帮助您提交错误报告。