1

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)

Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
Voxel
  • 64
  • 9

1 Answers1

3

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;
Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
  • No, I explained in my question, "however, 'pushMatrix()' does not exist in my code." – Voxel May 11 '22 at 17:12
  • 1
    @Voxel It literally does. EDIT: In many places. Are you sure you ran the updated code? – MarkusMulholland May 11 '22 at 17:14
  • 1
    @Voxel You are calling `pushMatrix()` on line 175 and a bunch of other places. Find and replace ALL of them with `push()` and do the same with `popMatrix()` to `pop()`. I did this and it got rid of your error. Here is the corrected code in the p5 web editor: https://editor.p5js.org/lindapaiste/sketches/loqBFD7i7 – Linda Paiste May 11 '22 at 17:16
  • 1
    In your `pastebin` link, a simple search for `pushmatrix` indicates there are 24 occurrences. A quick find-and-replace would do the trick as @LindaPaiste said. – Bumhan Yu May 11 '22 at 17:18
  • I think you must have had a `pushMatrix` in there by accident when you got the error the first time (when you said that you were using `push()`) – Linda Paiste May 11 '22 at 17:19
  • 1
    Whoops! I pasted the wrong code! When I removed the pushMatrix() and popMatrix() before, it actually didn't take effect because I didn't press the stop button first. It's no longer complaining. – Voxel May 11 '22 at 17:19
  • Glad I could help :) It's an easy fix. – Linda Paiste May 11 '22 at 17:23