Home > Blockchain >  Error in p5.js: "pushMatrix() not used, see push()"
Error in p5.js: "pushMatrix() not used, see push()"

Time:05-12

Every time I run my code, it gives me an error:

p5.js says: An error with message "pushMatrix() not used, see push()" occured inside the p5js library when pushMatrix was called (on line 175 in sketch.js [/sketch.js:175:13])

If not stated otherwise, it might be an issue with the arguments passed to pushMatrix. (http://p5js.org/reference/#/p5/pushMatrix)

However, pushMatrix() does not exist in my code. When I try to fix it by replacing push() with pushMatrix(), it gives me the same error:

p5.js says: An error with message "pushMatrix() not used, see push()" occured inside the p5js library when pushMatrix was called (on line 175 in sketch.js [/sketch.js:175:13])

If not stated otherwise, it might be an issue with the arguments passed to pushMatrix. (http://p5js.org/reference/#/p5/pushMatrix)

My code: https://pastebin.com/gMxwvJLA (StackOverflow wouldn't let me post the question because the code was so large)

CodePudding user response:

In short: pushMatrix() is not a valid function in p5. It doesn't exist. You want to find and replace all usages of pushMatrix() with push() and popMatrix() with pop().

With those replacements your code runs without any errors and I see a square spinning around in the center of the canvas.

The error message is not particularly helpful, but looking at the source code clarifies things a lot.

/**
 * @for p5
 * @requires core
 * These are functions that are part of the Processing API but are not part of
 * the p5.js API. In some cases they have a new name, in others, they are
 * removed completely. Not all unsupported Processing functions are listed here
 * but we try to include ones that a user coming from Processing might likely
 * call.
 */

import p5 from './main';

p5.prototype.pushStyle = function() {
  throw new Error('pushStyle() not used, see push()');
};

p5.prototype.popStyle = function() {
  throw new Error('popStyle() not used, see pop()');
};

p5.prototype.popMatrix = function() {
  throw new Error('popMatrix() not used, see pop()');
};

p5.prototype.pushMatrix = function() {
  throw new Error('pushMatrix() not used, see push()');
};

export default p5;
  • Related