Closed Bug 517056 Opened 15 years ago Closed 14 years ago

Canvas.drawImage throws exception if image isn't loaded

Categories

(Core :: Graphics: Canvas2D, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla2.0b1

People

(Reporter: davidj, Assigned: bzbarsky)

References

()

Details

Attachments

(1 file, 1 obsolete file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)

If you call Canvas.drawImage and the image hasn't loaded, Firefox throws an NS_ERROR_NOT_AVAILABLE error. According to the docs it should halt the script until the image has loaded.

Reproducible: Always

Steps to Reproduce:
1. var img = new Image()
2. img.src = ...
3. ctx.drawimage(img, 0, 0);

(make sure you shift+reload the page, so that it has to reload the image).
Actual Results:  
Should draw the image.

Expected Results:  
Returns this error:
uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMCanvasRenderingContext2D.drawImage]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://dev.groupboard.com/drawimage.html :: draw
(In reply to comment #0)
> If you call Canvas.drawImage and the image hasn't loaded, Firefox throws an
> NS_ERROR_NOT_AVAILABLE error. According to the docs it should halt the script
> until the image has loaded.

That's not correct; the spec states:

> If the image argument is an HTMLImageElement  object whose complete  attribute is false, or if the image argument is an HTMLVideoElement  object whose readyState  attribute is either HAVE_NOTHING  or HAVE_METADATA, then the implementation must return without drawing anything.

Our implementation was done before that was added to the spec; so the only change here would be that we should just not throw an exception.  But script execution won't ever block until the image is loaded.
The developer documentation states:

>If loading isn't finished when a drawImage statement gets executed, the script halts until the image is finished loading.

Perhaps the developer documentation is just wrong and needs updated.
Confirming this; this recently came up on the whatwg mailing list too.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached patch Possible patch (obsolete) — Splinter Review
Though note comments for image elements.  I can add another QI to do what the spec says for HTMLImageElement if we want to be safe...  But I'd rather see what the response is to my suggesting that other images be usable here and how the spec changes as a result.
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
Attachment #450656 - Flags: review?(vladimir)
Attachment #450656 - Attachment is obsolete: true
Attachment #450658 - Flags: review?(vladimir)
Attachment #450656 - Flags: review?(vladimir)
Comment on attachment 450658 [details] [diff] [review]
And actually including the test

Looks good to me; what other images are you referring to?  Video etc?
Attachment #450658 - Flags: review?(vladimir) → review+
> what other images are you referring to?

<input type="image">, <object src="some image">, <svg:image>.
Pushed http://hg.mozilla.org/mozilla-central/rev/391f93244331
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a6
Boris, you might want to have a look at bug 574330 - I think your fix for this bug might have caused another bug.
It couldn't have, since all the comments in bug 574330 are about 1.9.2, and this change was made only on 2.0.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: