Skip to content

Remove warning with zero size & RESIZABLE in display.set_mode #3386

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

Merged
merged 3 commits into from
Mar 24, 2025

Conversation

damusss
Copy link
Member

@damusss damusss commented Mar 14, 2025

Probably fixes #3385 .
NEW approach: don't warn if (0, 0) size is used with pygame.RESIZABLE. Explanation below
I humbly ask @oddbookworm (original implementation) and Kennedy Richard (issue opener) to test this PR if they can to see if it is fixed.

@damusss damusss added bug Not working as intended display pygame.display labels Mar 14, 2025
@damusss damusss requested a review from a team as a code owner March 14, 2025 23:39
@KennedyRichard
Copy link

I humbly ask @\oddbookworm (original implementation) and Kennedy Richard (issue opener) to test this PR if they can to see if it is fixed.

I'd love too, but I'm not tech savvy when it comes to using pygame-ce directly from the repo (I usually only install it directly from pip). Is there any compilation steps required? Whichever the case, if there's any sort of guide I can follow available, I'd love to follow it and report my results.

@oddbookworm
Copy link
Member

I'd love too, but I'm not tech savvy when it comes to using pygame-ce directly from the repo (I usually only install it directly from pip). Is there any compilation steps required? Whichever the case, if there's any sort of guide I can follow available, I'd love to follow it and report my results.

You just need to install the correct wheel from the CI. Since you're on linux and python 3.10, I'll grab the appropriate wheel for you and post that here for you in a sec. Then you can just pip install it

@oddbookworm
Copy link
Member

Unzip this and then pip install it (I'm assuming you're on x86_64 lol)
pygame_ce-2.5.4.dev1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.zip

@KennedyRichard
Copy link

Sorry for the wait, I had to test under different circumstances to check a few assumptions.

It didn't solve the problem (at least in my system). However, I noticed that the warning appears when I set the flag to RESIZABLE. If I don't set a flag, the warning doesn't appear, even though I set the size to (0, 0). I didn't test with other flags though.

I tested the wheel both with Nodezator and with this small fixture I put together:

from random import randint

import pygame as pg



pg.init()

sc = pg.display.set_mode((0, 0), pg.RESIZABLE)

scr = sc.get_rect()
bg = pg.Surface(sc.get_size()).convert()
bg.fill('white')

circle = pg.font.Font(None, 200).render('\N{bullet}', True, 'black').convert_alpha()
circle_rect = circle.get_rect()
circle_rect.center = scr.center


running = True

maintain_fps = pg.time.Clock().tick

while True:

    maintain_fps(30)

    ###

    for event in pg.event.get():

        if event.type == pg.QUIT:

            pg.quit()
            quit()

        elif event.type == pg.KEYDOWN:

            if event.key == pg.K_ESCAPE:

                pg.quit()
                quit()

    ###

    sc.blit(bg, (0, 0))

    circle_rect.move_ip(randint(0, 20), randint(0, 20))

    if not scr.colliderect(circle_rect):
        circle_rect.center = scr.center

    sc.blit(circle, circle_rect)

    ###

    pg.display.update()

@KennedyRichard
Copy link

Here where I live it is starting to get late, so I have to retire for the night. I also have a commitment for the entire morning, so if you still require my assistance I'll be glad to help when I get back to my pc tomorrow after lunch.

@oddbookworm
Copy link
Member

Unfortunately, I can't currently reproduce this on my end either. My current linux install is being too nice, so you might be the only one currently available to test this...

@oddbookworm
Copy link
Member

Ok, I couldn't reproduce the issue you reported, but the issue present with RESIZABLE windows is reproducible. Here's a snip of some outputs I produced by slightly modifying the output message
image

@oddbookworm
Copy link
Member

oddbookworm commented Mar 15, 2025

So RESIZABLE windows are actually still subject to being force resized by the OS, and my warning is properly working. We're properly scaling it to the monitor's size, but then the OS is slighly scaling it down (probably to account for things like the task bar). We can probably add in an exception to just suppress the warning in this very specific case where we scale up a (0, 0) window with the RESIZABLE flag and the OS resizes it back down

@damusss
Copy link
Member Author

damusss commented Mar 15, 2025

Alright @oddbookworm I'll do that. It makes sense, because we were already deciding the size of the window ourselves, so it doesn't make sense to warn if the size we chose wasn't liked by the OS. The size was going to be different from (0,0) anyways

@damusss damusss changed the title Fix warning false positives with zero size in display.set_mode Remove warning with zero size & RESIZABLE in display.set_mode Mar 15, 2025
@damusss damusss added bugfix PR that fixes bug and removed bug Not working as intended labels Mar 15, 2025
@KennedyRichard
Copy link

Ok, I couldn't reproduce the issue you reported, but the issue present with RESIZABLE windows is reproducible.

Don't worry, the RESIZABLE flag was also causing the problem. It just happens that when I posted the issue I hadn't realized this yet, but as I said after, the RESIZABLE flag was indeed part of the problem:

I noticed that the warning appears when I set the flag to RESIZABLE. If I don't set a flag, the warning doesn't appear, even though I set the size to (0, 0)

Since your new solution takes this into account I believe it should work now for everyone. Even so, I'll test it again here in my system, I think I figured out where to grab a wheel (on the Actions tab of the repo, from the item that has the same name as this PR).

@KennedyRichard
Copy link

Okay, confirmed: the new changes solve the issue here on my end as well.

Thank you all again for the awesome work. 👍

@KennedyRichard
Copy link

Just one more question, if I may: would it be safe to assume these changes will make into 2.5.4?

Just wanted to know because I put an if-else clause in Nodezator that will suppress the warning in case the size is (0, 0), the flag is RESIZABLE and pygame-ce versions are 2.5.2 (when the bug was introduced) or 2.5.3 (the current version where the bug persists).

@damusss
Copy link
Member Author

damusss commented Mar 15, 2025

@KennedyRichard yes, this bugfix will be released with version 2.5.4 since the previous ones are already released. You may suppress this warning for 2.5.2 and 2.5.3.

Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! ⭐

Copy link
Member

@oddbookworm oddbookworm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@oddbookworm oddbookworm added this to the 2.5.4 milestone Mar 24, 2025
@oddbookworm oddbookworm merged commit e3db181 into pygame-community:main Mar 24, 2025
27 checks passed
@damusss damusss deleted the setmode-0size-warning-fix branch March 24, 2025 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR that fixes bug display pygame.display
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pygame.display.set_mode printing RuntimeWarning when size set to (0, 0)
4 participants