Skip to content

FireFox: _drawImage may fail #285

Open

Description

@ximonn

On FireFox 18.0.2, on mac os Lion

Minor Issue: NS Error in firefox when drawing image on image loaded event.

Description:
If you draw an image on a layer on the image loaded event,
in FireFox the image might not be completely loaded yet.
Resulting in an error: component not available
This error will stop the app.

Workaround:
Quick and dirty workaround is to place a try{ } catch(err){} around the drawImage method.

As the draw fails in the startup of the app - on image loaded events, the image will be drawn later again by one of the layer.draw() calls. So from user perspective there is no penalty in the workaround.

I havent investigated deeply into the issue. Though this only happens with Firefox.
Since this issue shows itself under load of an app using many images and moving them around at startup I dont have an isolated fiddle demonstrating the issue.

The inspiration for the workaround came from:
https://bugzilla.mozilla.org/show_bug.cgi?id=574330

_drawImage: function(context, a) {
      try {
        if(a.length === 5) {
            context.drawImage(a[0], a[1], a[2], a[3], a[4]);
        }
        else if(a.length === 9) {
            context.drawImage(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
        }
      }
      catch(err){
        console.log("_drawImage err:",err);
      }
    }

If the try - catch is not really a performance impact, I suggest considering adding it to at least not let an app fail in Firefox when this happens.

Example error output on the console in FF:

[15:13:16.194] _drawImage err: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://www.shopaunt.com/lib/kinetic-v4.3.3.js :: <TOP_LEVEL> :: line 5787" data: no]

Note: adding the following check - catches part of the cases but in my experience not all of them:

if (!a[0].complete) {
     console.log("argl no drawImage");
}
else {
   // do the draw
}

Cheers,
Simon

Activity

  1. ericdrowell commented on Feb 21, 2013

    @ericdrowell
    Owner

    thanks for looking into this! I'll try and get this in asap

  2. umesh25 commented on May 25, 2013

    @umesh25

    hello , i also getting same ERROR using kinetic js-v4.3.3 , is there any solution for this type of issue. ? please reply asap.. thanx

  3. ximonn commented on May 25, 2013

    @ximonn
    Author

    If you have a jsfiddle which reproduces it? you can try out one of the work arounds.
    For myself I havent seen the issue in a while, Im using kinetic-v4.5.1.js

  4. dvsmaximaa commented on Dec 11, 2013

    @dvsmaximaa

    hello , i am also getting same ERROR using kinetic js-v4.7.2 , is there any solution for this type of issue. ? please reply me..i am frustate due to this error. thanx

  5. ximonn commented on Dec 11, 2013

    @ximonn
    Author

    @dvsmaximaa did you try the workaround? use the uncompressed kinetics 4.7.2 file and lookup the _drawImage function and do the same change.

  6. dvsmaximaa commented on Mar 13, 2014

    @dvsmaximaa

    Which kind of changes i do to solved this error becuase still i am getting same ERROR using kinetic js-v5.0.1 , is there any solution for this type of issue. ? please reply me

  7. dvsmaximaa commented on Mar 13, 2014

    @dvsmaximaa

    when will Release kinetic version 5.1.0 ?? any one know..??

  8. prasadKodeInCloud commented on Apr 7, 2014

    @prasadKodeInCloud

    Hi,
    Plz fix this issue.our tool is in trouble bcs of this

  9. HemanthFromIndia commented on Apr 24, 2014

    @HemanthFromIndia

    Hi, same problem here. Please give the patch for the same.

  10. lavrton commented on Apr 24, 2014

    @lavrton
    Contributor

    Is this workaround working for you?

    image.onload = function() {
      if (!image.complete) {
        image.src = image.src;
        return;
      }
      // Insert your code here
    };
  11. mattslocum commented on Apr 25, 2014

    @mattslocum
    Contributor

    It happens for me in kinetic-v5.1.0.js:1713
    It appears to be when when FF is having performance trouble. Images that are already loaded in memory become not ready. From what I can tell FF has had this problem for many years now. https://bugzilla.mozilla.org/show_bug.cgi?id=574330

    FF memory consuption spikes to around 1.8GB during this problem, and then drops back down to 200MB or so when it catches back up.
    Adding:
    if (!a[0].complete) return '';
    stopped FF from throwing the error and causeing weird rendering artifacts.

    I'm wondering if before return ''; we should throttle back the frameRate until FF catches up, since it would be clear that FF is having performance problems when that condition happens.

  12. lavrton commented on Apr 27, 2014

    @lavrton
    Contributor

    I think that including such workaround with try:

    try {
            if(a.length === 5) {
                context.drawImage(a[0], a[1], a[2], a[3], a[4]);
            }
            else if(a.length === 9) {
                context.drawImage(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
            }
    } catch(err) {}

    is bad idea. Thoughts:

    1. It may break performance
    2. Unexpected "invisible" image.

    If you want to check is image is ok, you may do this:

    layer.add(image);
    try {
      layer.draw();
    } catch (e) {
      // ops...
    }
  13. lavrton commented on Apr 27, 2014

    @lavrton
    Contributor

    Also you can use this small snippet:

    if (Kinetic.UA.browser === "mozilla") {
            var originDraw = Kinetic.Context.prototype.drawImage;
            Kinetic.HitContext.prototype.drawImage = Kinetic.SceneContext.prototype.drawImage = function() {
              try {
                originDraw.apply(this, arguments);
              } catch (e) {
                 console.log(e);
              }
            };
          }
  14. mattslocum commented on Apr 27, 2014

    @mattslocum
    Contributor

    For me the problem is not with the image. The image is already loaded and being used in the canvas. The problem happens during animation ticks. It feels like sometimes Firefox has performance issues and isn't able to deliver the image during the redraw of the animation tick.

    I like your solution with the Kinetic.UA.browser === "mozilla" for now. I might do a variation on that until I have a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions