Closed Bug 1260711 Opened 4 years ago Closed 4 years ago

Error "IndexSizeError: Index or size is negative or greater than the allowed amount" when using the animation inspector

Categories

(DevTools :: Inspector: Animations, defect, P2)

defect

Tracking

(firefox48 fixed)

RESOLVED FIXED
Firefox 48
Tracking Status
firefox48 --- fixed

People

(Reporter: pbro, Assigned: nchevobbe)

Details

(Whiteboard: [btpp-fix-later])

Attachments

(1 file)

I have no STRs for this yet, but I have seen this a few times, and at least 2 persons have reported this on IRC today.
When using the animation inspector, the following errors may be logged:

JavaScript error: resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/client/animationinspector/utils.js, line 87: IndexSizeError: Index or size is negative or greater than the allowed amount

The corresponding piece of code is this:

function drawGraphElementBackground(document, id, graphWidth, intervalWidth) {
  let canvas = document.createElement("canvas");
  let ctx = canvas.getContext("2d");

  // Set the canvas width (as requested) and height (1px, repeated along the Y
  // axis).
  canvas.width = graphWidth;
  canvas.height = 1;

  // Create the image data array which will receive the pixels.
  let imageData = ctx.createImageData(canvas.width, canvas.height);
  [...]

So, it looks like graphWidth may be either negative or too large in some cases, and that causes ctx.createImageData to fail.
Assignee: nobody → chevobbe.nicolas
I can see the error happening in a test : 

`/mach test devtools/client/inspector/computed/test/browser_computed_cycle_color.js`

( running the test in chaos mode - `SimpleTest.testInChaosMode();`- might help trigger it )

Now the cause: in animation-timeline, there's a resize event handler on the window.
The handler then calls drawGraphElementBackground  with the header offsetWidth.
While running this test, the said offsetWidth would be "0", and that's what throws when assigning calling `createImageData`.

You can see the error in running the following in the webconsole : 
`
var cvs = document.createElement("canvas");
var ctx = cvs.getContext("2d");
var imageData = ctx.createImageData(0, 1);
`

By the way, maybe we should file a bug for the message "IndexSizeError: Index or size is negative or greater than the allowed amount", as it doesn't really describe the problem ( 0 is not negative, nor "too great" )
Status: NEW → ASSIGNED
than the allowed amount' when using the animation inspector. r=pbro

Error was raised in drawGraphElementBackground when called with the graphView
being `0` This could happen because in animation-timeline.js , there is a
resize event handler that could be fired while the animation panel width is 0.
We fix this by making sure the animation panel does not have a width of zero
in the resize handler.

Review commit: https://reviewboard.mozilla.org/r/43275/diff/#index_header
See other reviews: https://reviewboard.mozilla.org/r/43275/
Attachment #8736411 - Flags: review?(pbrosset)
Comment on attachment 8736411 [details]
MozReview Request: Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater than the allowed amount' when using the animation inspector. r=pbro

https://reviewboard.mozilla.org/r/43275/#review40021

This makes sense. Thanks for quickly fixing this.
Just so you are aware, bug 1260912 will be a better long term plan for this. But I'm happy to ship this change nonetheless because it's small/quick/ready to land.
Attachment #8736411 - Flags: review?(pbrosset) → review+
Comment on attachment 8736411 [details]
MozReview Request: Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater than the allowed amount' when using the animation inspector. r=pbro

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/43275/diff/1-2/
Attachment #8736411 - Attachment description: MozReview Request: Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater → MozReview Request: Bug 1260711 - Fix error 'IndexSizeError: Index or size is negative or greater than the allowed amount' when using the animation inspector. r=pbro
https://hg.mozilla.org/mozilla-central/rev/ad16491227f9
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 48
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.