Skip to content
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

Refactored the createGraphics function in rendering.js #6557

Merged
14 changes: 9 additions & 5 deletions src/core/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,17 @@ p5.prototype.noCanvas = function() {
* @param {HTMLCanvasElement} [canvas]
* @return {p5.Graphics} offscreen graphics buffer
*/
p5.prototype.createGraphics = function(w, h, renderer, canvas) {
if (arguments[2] instanceof HTMLCanvasElement) {
renderer = constants.P2D;
canvas = arguments[2];
p5.prototype.createGraphics = function(w, h, ...args) {
/**
* args[0] is expected to be renderer
* args[1] is expected to be canvas
*/
if (args[0] instanceof HTMLCanvasElement) {
args[1] = args[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is a bug: args[1] will also be constants.P2D because you are setting it equal to args[0] after resetting that to be constants.P2D.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! I was thinking the same. Maybe using a temporary variable could do the trick? What do you reckon?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work, or alternatively just setting args[1] before args[0].

args[0] = constants.P2D;
}
p5._validateParameters('createGraphics', arguments);
return new p5.Graphics(w, h, renderer, this, canvas);
return new p5.Graphics(w, h, args[0], this, args[1]);
};

/**
Expand Down
Loading