Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 5, 2018. It is now read-only.
This repository was archived by the owner on Dec 5, 2018. It is now read-only.

When mouseX and mouseY are read inside mouseClicked(), they are not guaranteed to correspond to the point where the mouse was clicked #184

Open
@teo1978

Description

@teo1978
void setup() {
  size(400,400);
  background(0);
}

void draw() {
  for (int i=0; i<1000000000; i++) {
    // Just pretending to do some CPU-heavy stuff
  }
}

void mouseClicked() {
  strokeWeight(10);
  stroke(255);
  point(mouseX,mouseY);
}

Steps to reproduce: (this is not systematic, you may have to try a few times until you observe the issue)

  • move the mouse to a certain point A and stay there for a while
  • quickly move to another point B, click immediately, and stay there

Expected:

  • There may be quite a delay before the dot is drawn, because draw() is consuming a lot of cpu time; however, the dot should appear at point B, where you clicked. That is, it should be 100% guaranteed that the value of mouseX and mouseY, when read inside mouseClicked(), correspond to the point where the cursor is when the mouse is clicked, since the API doesn't pass you the position of the click in any other manner.

Observed:

  • often, the dot is drawn at point A, or somewhere midway between A and B. That is, the value of mouseX and mouseY, when read in mouseClicked(), is "out of date", i.e. it correspond to a point where the cursor was some time before the actual click.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions