Skip to content

p5.Graphics throws error if try to draw shape before specifying a fill or stroke (v1.2.0) #4983

@JetStarBlues

Description

@JetStarBlues

Most appropriate sub-area of p5.js?

  • Accessibility (Web Accessibility)
  • Build tools and processes
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Friendly error system
  • Image
  • IO (Input/Output)
  • Localization
  • Math
  • Unit Testing
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)

Details about the bug:

  • p5.js version: 1.2.0
  • Web browser and version: All
  • Operating System: Windows
  • Steps to reproduce this:
    1. Download the 1.2.0 release
    2. Run the following snippet:
var buffer;

function setup ()
{
	createCanvas( 400, 400 );

	buffer = createGraphics( width, height );
	makeCircleBuffer();
}

function draw ()
{
	image( buffer, 0, 0 );  // draw pre-rendered image
}

function makeCircleBuffer ()
{
	/* Throws error if one of the following is not called first.
	*/
	//	buffer.background( 100 );
	//	buffer.fill( 255, 0, 0 );
	//	buffer.stroke( 255, 0, 0 );


	buffer.rect( 200, 200, 100, 100 );
	// buffer.ellipse( 200, 200, 300, 300 );
}

When you try to draw a shape to the buffer without first specifying either the background, fill, or stroke colours, you get a "TypeError". Expected behaviour: when the color is not specified, use the default of white fill or black stroke without throwing an error.

I am unable to reproduce the bug on the p5.js web editor. The editor is running the 1.1.9 release and renders a white filled, black stroked shape as expected.

Here is the error shown in Chrome 87.0:

p5.js:56173 Uncaught (in promise) TypeError: Cannot read property 'grid' of undefined
    at _main.default.Graphics._main.default._renderRect (p5.js:56173)
    at _main.default.Graphics._main.default.rect (p5.js:56089)
    at makeCircleBuffer (sketch_bufferTest_IssueMVC.js:26)
    at setup (sketch_bufferTest_IssueMVC.js:8)
    at _setup (p5.js:51363)
    at _runIfPreloadsAreDone (p5.js:51300)
    at p5._decrementPreload (p5.js:51310)
    at p5.<anonymous> (p5.sound.min.js:2)

Here is the error shown in Firefox 83.0:

Uncaught (in promise) TypeError: this._accessibleOutputs is undefined
    _renderRect             http://localhost:4000/p5js/1.2.0/build/p5/p5.js:56173
    rect                    http://localhost:4000/p5js/1.2.0/build/p5/p5.js:56089
    makeCircleBuffer        http://localhost:4000/bareMin/sketch_bufferTest_IssueMVC.js:26
    setup                   http://localhost:4000/bareMin/sketch_bufferTest_IssueMVC.js:8
    _setup                  http://localhost:4000/p5js/1.2.0/build/p5/p5.js:51363
    _runIfPreloadsAreDone   http://localhost:4000/p5js/1.2.0/build/p5/p5.js:51300
    _decrementPreload       http://localhost:4000/p5js/1.2.0/build/p5/p5.js:51310
    t                       http://localhost:4000/p5js/1.2.0/build/p5/addons/p5.sound.min.js:2
    promise callback*       http://localhost:4000/p5js/1.2.0/build/p5/addons/p5.sound.min.js:2
    p5                      http://localhost:4000/p5js/1.2.0/build/p5/p5.js:51568
    p5                      http://localhost:4000/p5js/1.2.0/build/p5/p5.js:51566
    _globalInit             http://localhost:4000/p5js/1.2.0/build/p5/p5.js:50603
    promise callback*[56]<  http://localhost:4000/p5js/1.2.0/build/p5/p5.js:50628
    o                       http://localhost:4000/p5js/1.2.0/build/p5/p5.js:34
    o                       http://localhost:4000/p5js/1.2.0/build/p5/p5.js:38
    [43]<                   http://localhost:4000/p5js/1.2.0/build/p5/p5.js:43475
    o                       http://localhost:4000/p5js/1.2.0/build/p5/p5.js:34
    r                       http://localhost:4000/p5js/1.2.0/build/p5/p5.js:51
    <anonymous>             http://localhost:4000/p5js/1.2.0/build/p5/p5.js:55
    <anonymous>             http://localhost:4000/p5js/1.2.0/build/p5/p5.js:18
    <anonymous>             http://localhost:4000/p5js/1.2.0/build/p5/p5.js:20

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