Skip to content

Fix #7259 TypeError for Offscreen Shapes #7626

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

Merged

Conversation

himanshuukholiya
Copy link
Contributor

@himanshuukholiya himanshuukholiya commented Mar 13, 2025

Resolves #7259

Fixes "TypeError: Cannot read properties of undefined" when drawing offscreen primitive shapes (ellipse(), line(), rect()) in p5.js.

This error occurs when we change y-coordinate to offscreen value like -1. The error is specific to y-coordinate changes and does not occur with x-coordinate changes.
Error message "Cannot read properties of undefined", pointing to an attempt to access an undefined object.

Changes:
Modify the _canvasLocator() in outputs.js to return null if a shape’s center is outside the canvas.
_canvasLocator() checks if the shape’s center (args[0], args[1]) is within 0 <= args[0] < canvasWidth and 0 <= args[1] < canvasHeight. If not, return null.

PR Checklist

Copy link

welcome bot commented Mar 13, 2025

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@himanshuukholiya himanshuukholiya changed the title Fix TypeError for Offscreen Shapes (#7259) Fix #7259 TypeError for Offscreen Shapes Mar 13, 2025
Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

This looks good, thanks! After I merge this in, would you be interested in applying the same fix in p5 2.0 in the dev-2.0 branch instead of main?

@davepagurek davepagurek merged commit a023d54 into processing:main Mar 16, 2025
2 checks passed
@himanshuukholiya
Copy link
Contributor Author

Sure @davepagurek! I'd be happy to apply the fix in the dev-2.0 branch. I'll get on it soon.
Thanks for merging!

@himanshuukholiya himanshuukholiya deleted the fix-7259-offscreen-shapes branch March 22, 2025 16:19
@himanshuukholiya himanshuukholiya restored the fix-7259-offscreen-shapes branch March 22, 2025 16:19
@himanshuukholiya himanshuukholiya deleted the fix-7259-offscreen-shapes branch March 22, 2025 16:26
@himanshuukholiya himanshuukholiya mentioned this pull request Mar 28, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mostly offscreen primitive shapes throws error
2 participants