[pygame] Bug: Circle tearing with mouse clicks within the window.

Skip to first unread message

Michael Baca

Dec 14, 2020, 10:00:37 PM12/14/20
to pygame...@seul.org
Python 3.8.6
Pygame 2.0.0
Xubuntu 20.10
Nvidia 1060 6GB

The following code, when run, causes an issue where the circle starts to tear as it moves across the screen if I click on the active window. Where I click seems to matter also, as the tearing can be adjusted by clicking at various points from top to bottom. I'm not checking for mouse events in the code, but I would imagine their still being tracked.

The tearing continues to happen after I've stopped and ran it again as well. It does go back to normal after a few tries. But the effects seem to stay in memory.

I wasn't sure where to send bugs, the website led me here. I hope this is the right place.

# ----------------------------------------
import pygame as pg

# init game space

screen = pg.display.set_mode((600, 400))
pg.display.set_caption("Ball Moving")

playerX = 50
playerY = 50
player_Width = 30
player_Height = 30
playerVelocity = 0.5

# Color Constants
BLUE = (0, 0, 255)

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

    # update screen
    keys = pg.key.get_pressed()
    if keys[pg.K_LEFT]:
        playerX -= playerVelocity
    if keys[pg.K_RIGHT]:
        playerX += playerVelocity
    if keys[pg.K_UP]:
        playerY -= playerVelocity
    if keys[pg.K_DOWN]:
        playerY += playerVelocity

    pg.draw.circle(screen, (BLUE), (playerX, playerY), player_Width, 0)


Michael Lutynski

Dec 14, 2020, 11:19:05 PM12/14/20
to pygame...@seul.org

Hello Michael and welcome to the community :)

I tried your code on my Linux setup: Python 3.8.5, Pygame 2.0.0, SDL 2.0.12, KDE neon 5.20.04, Mesa DRI Intel HD Graphics 3000...

After adding the missing

     WHITE = (255, 255, 255)

and running your code, I didn't notice tearing as I moved the circle around. But for me, KDE uses KWin, which is a composited window manager. Is Xubuntu using XFWM? I'm going out on a limb, but I think that is not a composited WM, and might have a different interaction with X11 and appear differently. Have you experimented with installing a different distro, like Kubuntu, then login and run your test and see if it behaves differently?

~ Michael

Greg Ewing

Dec 15, 2020, 12:31:12 AM12/15/20
to pygame...@seul.org
On 15/12/20 4:00 pm, Michael Baca wrote:
> The following code, when run, causes an issue where the circle starts to
> tear as it moves across the screen

You could try

screen = pg.display.set_mode((600, 400),
flags = pg.HWSURFACE | pg.DOUBLEBUF)

According to the docs, this will cause screen.flip() to wait for
a vertical retrace.

Reply all
Reply to author
0 new messages