Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:04:29+00:00 2026-05-27T22:04:29+00:00

Sometimes I some errors like this one when I’m working with canvas on Firefox:

  • 0

Sometimes I some errors like this one when I’m working with canvas on Firefox:

Error: uncaught exception: [Exception… “Component returned failure
code: 0x80004005 (NS_ERROR_FAILURE)
[nsIDOMCanvasRenderingContext2D.lineWidth]” nsresult: “0x80004005
(NS_ERROR_FAILURE)” location: “JS frame ::
media/js/canvas/Rectangle.js :: :: line 34” data: no]

It happens when i’m working with more than 5 canvas elements, on a for loop. The function what creates them is this:

function addCanvas(id) {
var canvas = document.getElementById(id);

if (canvas == null) {
    $('#content').append(
        '<canvas id="' + id + '" width="' + workAreaWidth +'" height="' 
            + workAreaHeight + '"></canvas>'
    );

    canvas = document.getElementById(id).getContext('2d');
} else {
    canvas = canvas.getContext('2d');
    canvas.setTransform(1, 0, 0, 1, 0, 0);
    canvas.clearRect(0, 0, workAreaWidth, workAreaHeight);
}   

return canvas;
}

The for loop is in another function.

What happens is that not all the canvas elements are updated. I guess cause of the exception.

I can’t post the code of the place where it exactly fails, cause it fails randomly in many places, always with the same error.

The Firefox version is 9.0, but also happened on 8.0.1. I didn’t test it on previous releases. My operating system is Mac Snow Leopard. I guess it will help. It doesn’t fail on Chrome or Safari,

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:04:29+00:00Added an answer on May 27, 2026 at 10:04 pm

    These error messages are confusing to the uninitiated, but there’s a lot of information packed into them. The important parts are:

    Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMCanvasRenderingContext2D.lineWidth]

    Ignore the hexadecimal number: this is telling you that the accessor nsIDOMRenderingContext2D.lineWidth returned a generic failure code (NS_ERROR_FAILURE) rather than a line width. nsIDOMRenderingContext2D is the internal name of the C++ class that implements the object you get back from getContext("2d") on a canvas element.

    location: “JS frame :: media/js/canvas/Rectangle.js :: :: line 34”

    The call from JavaScript into the C++ method that failed is at line 34 of media/js/canvas/Rectangle.js. That’s your code. That is not, however, the code that you quoted, but maybe we can figure out what’s wrong by looking at the code for the accessor that failed: http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#3180

    nsresult
    nsCanvasRenderingContext2D::GetLineWidth(float *width)
    {
        if (!EnsureSurface())
            return NS_ERROR_FAILURE;
    
        gfxFloat d = mThebes->CurrentLineWidth();
        *width = static_cast<float>(d);
        return NS_OK;
    }
    

    Okay, so the only way that can fail is if EnsureSurface fails. That is defined at http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#1154 and I’m not going to quote it here because it’s huge and has a whole bunch of ways it can fail. However, it looks to me like one of your canvas elements is either not properly defined, or is not being given a chance to initialize itself (i.e. you need to allow the event loop to run).

    EDIT: Concrete advice: Change the function you quoted to be like this:

    function addCanvas(id, continuation) {
        if (document.getElementById(id) === null) {
            $('#content').append(
                '<canvas id="' + id + '" width="' + workAreaWidth +'" height="' 
                + workAreaHeight + '"></canvas>'
            );
        }
    
        setTimeout(function() {
            var canvas = document.getElementById(id).getContext('2d');
            canvas.setTransform(1, 0, 0, 1, 0, 0);
            canvas.clearRect(0, 0, workAreaWidth, workAreaHeight);
            continuation(canvas);
        }, 0);
    }
    

    You’ll also need to change all callers to match. I do not guarantee that this will work, but it’s the most plausible thing I can think of.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes when some feature requires many different settings, they are written in a cloze
Sometimes I create some quick personal projects using C# with Windows Forms or WPF
I sometimes check out some previous version of the code to examine or test.
Sometimes I need to find some strings inside DB usually it is just host-name
Sometimes I need to quickly extract some arbitrary data from XML files to put
Sometimes it's difficult to describe some of the things that us programmers may think
Sometimes for testing/developing purposes we make some changes in the code that must be
We have some input data that sometimes appears with &nbsp characters on the end.
We have some applications that sometimes get into a bad state, but only in
Sometimes a loop where the CPU spends most of the time has some branch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.