Error "Failed to execute 'arcTo'" when doing calculation with width or height fields in the setup().

I have an error of which happens every time I do calculation with width or height in the setup() function.

The error is this.

p5.js:15092 Uncaught IndexSizeError: Failed to execute 'arcTo' on 'CanvasRenderingContext2D': The radius provided (-2) is negative.

Here is an example. Note line 10.

This code will not working.

The error is like this.

However changing the line 10 into this make the application works again.

Is this behavior intended? How can I do calculation with width and height in the setup() function?


  • Well I just got something interesting.

    width/60 returns the error.

    However, width/16 (with smaller denominator) it is working.

    So I assume that the size of the shape I am going to make is too small with width/60?

  • Answer ✓

    How do you expect us to help when you don't post your full source code? :-/

    The error message seems fairly clear however:

    The radius provided (-2) is negative

    Are you subtracting something from the width/# calculation to get the value passed as a radius?

  • I did post the code above. Some people in other threads and forums insist me to put small code snippet instead of the long full code when asking question. So I am sorry for the inconvenience.

    Yeah it seems I do a subtraction that reduces a variable that will be used in shape calculation to zero. I fix this by making some if statements to prevent some values to go less than zero.

    Anyway thanks for the insight.

  • It's true that it's not a good idea to post really long sketches here; but we need enough code to be able to understand what you're doing :P

    In this case the issue had nothing to do with the condition you posted the 'source' of; but the point at which the variable was being used...

    You should also post code in text format and not as images: then we can copy/paste short sketches and test them directly.

    Finally you may find Math.abs() useful...

Sign In or Register to comment.