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

mouseY system variable eventually stops working #7392

Open
1 of 17 tasks
HectorDev309 opened this issue Nov 26, 2024 · 11 comments
Open
1 of 17 tasks

mouseY system variable eventually stops working #7392

HectorDev309 opened this issue Nov 26, 2024 · 11 comments

Comments

@HectorDev309
Copy link

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

v1.9.4 May 21, 2024

Web browser and version

Firefox 115.17.0esr

Operating system

Windows 7

Steps to reproduce this

I don't know what exactly causes this, but the mouseY system variable eventually starts returning floating numbers making no sense with the current mouse Y position.

I coded a simple program that shows the current mouseY value and it works properly, but if you make a full project it works for a short period and eventually starts showing incoherent results until you rerun the program, but it keeps happening again and again.

I had this problem with two projects of mine, I couldn't notice any similarity between then that could be causing this problem, but I will try to find something while I wait for a answer.

With one of those projects I managed to avoid this issue by creating a new variable for the mouse Y position and using movedY to change the value of the variable, it worked, but the mouseY variable would be more reasonable.

Copy link

welcome bot commented Nov 26, 2024

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@HectorDev309
Copy link
Author

I managed to fix it after I checked this issue.

The issue is talking about a problem with out-of-Ybounds shapes, there is a comment there mentioning problems with the mouseY variable.

I had the same issue as this user and I managed to fix it by adding gridOutput = function(){} inside the setup() function and so I did the same at the projects I mentioned in my issue and it fixed my problem as well.

Still, this is a bit problematic because it's disabling a built-in function, I'm not using it, but still, could cause more problems to some people.

@bojidar-bg
Copy link

For completeness sake... is the issue fixed in newer versions of p5.js, e.g. 1.10 and above, that include the fix from 46c5226?

@HectorDev309
Copy link
Author

HectorDev309 commented Nov 26, 2024

For completeness sake... is the issue fixed in newer versions of p5.js, e.g. 1.10 and above, that include the fix from 46c5226?

I added the 1.11.1 p5.js version to the HTML file and removed the gridOutput = function(){} from the setup() function... the issue returned...

Then I added gridOutput = function(){} again and the issue was fixed.

@HectorDev309 HectorDev309 reopened this Nov 26, 2024
@bojidar-bg
Copy link

bojidar-bg commented Nov 26, 2024 via email

@HectorDev309
Copy link
Author

As I said before, I don't know exactly what causes the problem, so I can't provide the specific steps to achieve the issue, but I can show you one of my projects.

The project itself is just a colorful circle showing the color of the current pixel hovered by the mouse at the top left and the mouseIndex, which is a variable representing the index of the pixel currently hovered by the mouse like it's on a pixels array.

The 7th line has the command gridOutput = function(){} fixing the issue, if you remove it the text at the top left starts showing incoherent numbers at some point.

At the 72nd line the mouseIndex variable is being set as an int, if you remove the int function along with the gridOutput = function(){} , instead of showing wrong numbers, the program will crash with an error

@bojidar-bg
Copy link

I can reproduce the sketch erroring out on Chromium if I remove the int call, then zoom the window in so that the canvas has a scrollbar, and then scroll the mouse wheel while moving the mouse. (Apparently, the smooth scrolling animation causes mouseY to be a floating-point value. As mouseY is not guaranteed to be an integer, this might be something better fixed by using an int(mouseY) than by changing anything in p5.js.) This way to reproduce seems hit the issue both with and without the gridOutput line however, so it's possible I'm hitting a different issue.
I fail to reproduce anything like this on Firefox, however.

@bojidar-bg
Copy link

@HectorDev309 Do you happen to have any other clues to what might be the steps to reproduce the issue? (Or whether my reproduction steps are correct?) Asking since I feel there might be something I've missed (:

@HectorDev309
Copy link
Author

@bojidar-bg I'm sorry for not answering, I actually ignored this issue, everytime I had any problem with the mouseY variable or the error mentioned in a previous comment about this issue of mine I simply added the gridOutput = function(){} line and kept coding with no problem.

I didn't find out too much, but here's what I have.

At first I thought we could reproduce this issue by using the mouseY somewhere in your code, but I had the same problem on projects where the mouseY variable wasn't being used at all, I was getting the same error message as this guy instead.

Apparently both issues are related somehow, since they can be fixed by the same command, maybe we could ask something to the guy who got the other issue.

@HectorDev309
Copy link
Author

@bojidar-bg About your try to reproduce the problem, I don't think this is related to the issue at all.

The steps you took made the mouseY variable assume a non-int value, that's true, but these steps are pretty difficult to happen naturally, maybe it's just a simple bug that can be forced.

The issue I had was about the mouseY variable starting to assume incoherent values at a certain point in the code's execution, the program starts normally, with the mouseY variable working properly, but if you move your mouse too much it starts to show weird values.

@bojidar-bg
Copy link

I tried moving my mouse around frantically, tabbing in and out, but I didn't get any kind of weird values 🤔 (tho I did need to do pixelDensity(1) to get the sketch working properly)

What do the incoherent mouseY values you get look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants