-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[p5.js 2.0 Beta Bug Report]: vertexProperty with single number arguments throws error #7518
Comments
See I think there was a issue with your vertexProperty Because when i looked it up in codebase it does not have vertexProperty function. Fixing the IssueSince Updated Working Codefunction setup() {
createCanvas(400, 400, WEBGL);
const pts = [];
for (let i = 0; i < 50; i++) {
pts.push(createVector(random(-width / 2, width / 2), random(-height / 2, height / 2)));
}
noFill();
beginShape();
for (let i = 0; i < pts.length; i++) {
let lengthValue = i / (pts.length - 1); // This is what `vertexProperty` was trying to set
// Instead of `vertexProperty`, just pass the values correctly to vertex functions
vertex(pts[i].x, pts[i].y, lengthValue);
}
endShape();
} What I Fixed:
|
hey @GregStanton I just came up with the fix but the problem is I dont know how to test it? Can u help me |
Hi @dhruvinjs! Thanks so much for taking a look at this one. The issue is that Here's the source code for If you check out the link I provided, you'll see that After the 2.0 release (scheduled by the end of March), contributing should get easier, but you're welcome to keep looking around for ways to help! In case you're still interested in the audit issue, I'll ping you there when I publish some specific tasks that need to be done. |
Hey @GregStanton first of all sorry for late message because this days I have been working for my personal project plus the I was completing but yeah now I will be tracking and if possible I will be sending a pr and plus I am still interested in the audit issue |
**Hey @GregStanton ** |
Possible Fix:You need to call Alternative Fix: Using
|
The spot where vertex properties are added to a shape happens here, after going from p5.prototype to p5.RendererGL to p5.Shape: p5.js/src/shape/custom_shapes.js Lines 806 to 813 in e35616f
So we already have some checking in place for whether or not the data is an array when we pick the size of the data. However, later on, we just set |
Hello @davepagurek , vertexProperty(name, data) {
this.userVertexProperties = this.userVertexProperties || {};
const key = this.vertexPropertyKey(name);
// Convert single value to array if it's not already an array
const dataArray = Array.isArray(data) ? data : [data];
if (!this.userVertexProperties[key]) {
this.userVertexProperties[key] = dataArray.length;
}
this.#vertexProperties[key] = dataArray;
} |
Most appropriate sub-area of p5.js?
p5.js version
2.0 beta 1
Web browser and version
Firefox
Operating system
MacOS
Steps to reproduce this
Steps:
vertexProperty
between each vertex0
) as opposed to an array (e.g.[0]
)This throws the error
Error: Can't convert 0 to array!
. If you use an array, there is no error. It should be converting to an array under the hood, but I must have messed that up in the shapes refactor.Snippet:
Live: https://editor.p5js.org/davepagurek/sketches/YPu6ixNV5
The text was updated successfully, but these errors were encountered: