pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
926 stars 154 forks source link

Delay after mouse click when using pygame.mouse.get_pos() on macOS #2280

Open makorendev opened 1 year ago

makorendev commented 1 year ago

Environment:

Current behavior:

When moving the mouse and clicking at the same time, the value returned from pygame.mouse.get_pos seems to pause for about 10 frames before updating normally again.

Expected behavior:

This function should return an accurate result every frame.

Screenshots

image

Steps to reproduce:

  1. Copy the code below into a blank script and run.
  2. Move the mouse around while clicking the left mouse button.
  3. Observe the circle pausing for a few frames after each click.

Test code

import pygame
pygame.init()
screen = pygame.display.set_mode((500, 500))

clock = pygame.time.Clock()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    clock.tick(60)

    pos = pygame.mouse.get_pos()

    screen.fill("black")
    pygame.draw.circle(screen, "red", pos, 25)
    print(pos)

    pygame.display.flip()

The issue persists with or without clock.tick.

ankith26 commented 1 year ago

Hello, thanks for the bug report. Can you test with another mouse, to eliminate any hardware issues? If that's not the fault, then maybe test with other applications to tell whether it's an os/driver issue?

I just tested with your code on my Ubuntu machine, I did not see anything wrong visually and there was no pausing, but maybe I'm not understanding your issue exactly

makorendev commented 1 year ago

I've tested with a separate wired mouse and I get the same issue. No other applications give me this issue, but I don't know if any of my other applications use SDL.

MyreMylar commented 1 year ago

Can't reproduce this on Windows with my Bluetooth mouse. I suspect this might be some kind of USB hardware issue.

Kn4ughty commented 7 months ago

Hello, I was looking through old issues just to see what was up and I was able to replicate this. M1 mac on MacOS sonoma. See attached video for it happening. To create this clip I bound right option to left click, and then moved around quickly on my touch pad. I did this because its very hard to click while moving correctly on a touch pad. I also slightly modified the code to show exactly when it is clicked.

(You might have to download the video to go frame by frame)

https://github.com/pygame-community/pygame-ce/assets/77908661/08840d14-9cc9-4b42-9be0-799b94aab694

Things of note, the position of the system mouse on screen freezes for a couple frames, then it moves and 1 frame later pygame detects the click. Then it takes 2 more frames for the position to update again.

The OS cursor freezing makes me maybe think its a MacOS issue, but I don't have any testing to support this and it seems unlikely. Probably its just the way MacOS handles touch pad input, I think for further testing the mouse should be moved by a program instead of a user to eliminate that sort of error. Might do it later