Skip to content

Reference to world.mouseSprites[0] is loss on mousedown #341

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

Open
juanparati opened this issue Apr 20, 2025 · 2 comments
Open

Reference to world.mouseSprites[0] is loss on mousedown #341

juanparati opened this issue Apr 20, 2025 · 2 comments

Comments

@juanparati
Copy link

juanparati commented Apr 20, 2025

I found an issue using P5 with P5Play and it's about that world.mouseSprites[0] is loss when a mouse click on a sprite.

The exception is raised is:

Uncaught ReferenceError: assignment to undeclared variable ms

raised in the following line:

if ($.world.mouseSprites.length) {
	let msm = $.world.mouseSprite?.mouse;
	// old mouse sprite didn't have the mouse released on it
	if (msm) {
		msm[btn] = 0;
		msm.hover = 0;
		msm.drag[btn] = 0;
	}
	ms = $.world.mouseSprites[0];
	$.world.mouseSprite = ms;    // <---- ERROR raised here
	msm = ms.mouse;
	msm[btn] = 1;
	if (msm.hover <= 0) msm.hover = 1;
}

It seems that after that "$.world.mouseSprites.length" condition is passed the reference to "$.world.mouseSprites[0]" is loss.

I tested this issue in Firefox and Safari with the same result.

Dependencies:

  • P5 1.11.5
  • P5Play 3.27.1

You can reproduce this issue in codesandbox:
https://codesandbox.io/p/github/juanparati/p5p5play-ts/main?import=true

Steps to reproduce:

  1. Mouse click on any sprite.
@juanparati
Copy link
Author

I found that this issue is also present with Q5 as well. It seems that this issue only happens when Q5 or P5 instance works in a non-global context.

@quinton-ashley
Copy link
Owner

thanks for reporting, I'll try fixing this tomorrow!

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

No branches or pull requests

2 participants