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

RESOLVED FIXED in Firefox 48

Status

()

Firefox
Developer Tools: Animation Inspector
P2
normal
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: pbro, Assigned: nchevobbe)

Tracking

unspecified
Firefox 48
Points:
---

Firefox Tracking Flags

(firefox48 fixed)

Details

(Whiteboard: [btpp-fix-later])

MozReview Requests

()

Submitter Diff Changes Open Issues Last Updated
Loading...
Error loading review requests:

Attachments

(1 attachment)

(Reporter)

Description

2 years ago
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)

Updated

2 years ago
Assignee: nobody → chevobbe.nicolas
(Assignee)

Comment 1

2 years ago
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" )
(Assignee)

Updated

2 years ago
Status: NEW → ASSIGNED
(Assignee)

Comment 2

2 years ago
Created 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

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/
(Assignee)

Updated

2 years ago
Attachment #8736411 - Flags: review?(pbrosset)
(Reporter)

Comment 3

2 years ago
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+
(Assignee)

Comment 4

2 years ago
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
(Assignee)

Comment 5

2 years ago
TRY run is over and everything is good : https://treeherder.mozilla.org/#/jobs?repo=try&revision=646aa0154197

There is an intermittent (https://treeherder.mozilla.org/#/jobs?repo=try&revision=646aa0154197&selectedJob=18854076, https://treeherder.mozilla.org/#/jobs?repo=try&revision=646aa0154197&selectedJob=18853656) that is known as Bug 1260714.
Keywords: checkin-needed

Comment 6

2 years ago
https://hg.mozilla.org/integration/fx-team/rev/ad16491227f9
Keywords: checkin-needed

Comment 7

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/ad16491227f9
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
status-firefox48: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 48
You need to log in before you can comment on or make changes to this bug.