Closed Bug 1389090 Opened 7 years ago Closed 3 years ago

After calling canvas.transferControlToOffscreen(), resizing canvas throws a NS_ERROR_FAILURE

Categories

(Core :: Graphics: CanvasWebGL, defect, P3)

x86_64
Windows 10
defect

Tracking

()

RESOLVED DUPLICATE of bug 1747476
Tracking Status
firefox57 --- wontfix

People

(Reporter: jujjyl, Unassigned)

References

Details

(Whiteboard: gfx-noted)

STR:

Enable gfx.offscreencanvas.enabled;true in about:config and

> <html><meta charset="utf-8"><body>
> <canvas id="canvas">
> <script>
> var canvas = document.getElementById("canvas");
> var offscreen = canvas.transferControlToOffscreen();
> canvas.width = 1000;
> </script></body></html>

Resizing the canvas on the last line gives an error "NS_ERROR_FAILURE: " thrown to the page console. Chrome Canary seems to be happy about this and does not produce errors.
Discussing with Justin Novosad, his thinking is that the correct pattern to change the size of the canvas would be

> var offscreen = canvas.transferControlToOffscreen();
> offscreen.width = 1000;

and that 

> canvas.width = 1000;

should throw an exception. If that is the case (the spec is a bit in flux with respect to this), then this bugzilla entry would turn to just changing the current exception string from "NS_ERROR_FAILURE: " to something more readable, like "Attempting to change the size of a Canvas element that has been transferred to OffscreenCanvas. Use the OffscreenCanvas object instead to change its size." or something similar.
(In reply to Jukka Jylänki from comment #1)
> Discussing with Justin Novosad, his thinking is that the correct pattern to
> change the size of the canvas would be
> 
> > var offscreen = canvas.transferControlToOffscreen();
> > offscreen.width = 1000;
> 
> and that 
> 
> > canvas.width = 1000;
> 
> should throw an exception. If that is the case (the spec is a bit in flux
> with respect to this), then this bugzilla entry would turn to just changing
> the current exception string from "NS_ERROR_FAILURE: " to something more
> readable, like "Attempting to change the size of a Canvas element that has
> been transferred to OffscreenCanvas. Use the OffscreenCanvas object instead
> to change its size." or something similar.

Follow the pattern to change the size of canvas, it still gets "NS_ERROR_FAILURE: " at https://codepen.io/daoshengmu/pen/qXPqvE. I agree we should add more readable messages for users.
Priority: -- → P3
Whiteboard: gfx-noted
The spec bug for mandating the thrown exception is at https://github.com/whatwg/html/pull/2951

We now throw InvalidStateError with a better message.

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.