Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ p5.prototype.windowHeight = 0;
p5.prototype._onresize = function(e) {
this._setProperty('windowWidth', getWindowWidth());
this._setProperty('windowHeight', getWindowHeight());
// Update mouse coordinates when window resizes
// This ensures mouseX/mouseY reflect the mouse position relative to the new canvas size
if (this._hasMouseInteracted && this._lastMouseEvent) {
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

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

The condition checks _hasMouseInteracted but this property may not be initialized. Consider adding a null check or ensuring this property is properly initialized before use.

Copilot uses AI. Check for mistakes.

Copy link
Author

Choose a reason for hiding this comment

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

_hasMouseInteracted is initialized to false on line 117 of mouse.js (p5.prototype._hasMouseInteracted = false;), so it's always defined.

this._updateNextMouseCoords(this._lastMouseEvent);
}
const context = this._isGlobal ? window : this;
let executeDefault;
if (typeof context.windowResized === 'function') {
Expand Down
2 changes: 2 additions & 0 deletions src/events/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ p5.prototype._updateNextMouseCoords = function(e) {
e
);

// Store the last mouse event for recalculating coordinates on resize
this._setProperty('_lastMouseEvent', e);

this._setProperty('mouseX', mousePos.x);
this._setProperty('mouseY', mousePos.y);
Expand Down