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

Fix pygame.camera backend detection on Windows Server #4221

Merged
merged 1 commit into from May 15, 2024

Conversation

andrigamerita
Copy link
Contributor

@andrigamerita andrigamerita commented May 3, 2024

The code for pygame.camera backend detection trips when running on a Server variant of modern Windows, causing initialization of the camera system to fail entirely, as can be seen in this traceback generated on my Windows Server 2022 system:

Traceback (most recent call last):
  File "<my client program>", line 5, in <module>
    pygame.camera.init()
  File "[...]\python-3.12.3.amd64\Lib\site-packages\pygame\camera.py", line 168, in init
    backends = [b.lower() for b in get_backends()]
                                   ^^^^^^^^^^^^^^
  File "[...]\python-3.12.3.amd64\Lib\site-packages\pygame\camera.py", line 128, in get_backends
    if sys.platform == "win32" and int(platform.win32_ver()[0].split(".")[0]) >= 8:
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '2022Server'

Obviously, Windows Server with the standard desktop environment installed runs the rest of pygame just fine, as it supports webcams at a system level just fine, and this issue has only to do with the version detection code being written without Server in mind.

This commit simply expands the Windows version checking code to make sure that both desktop and Server Windows are handled correctly. I checked how Python returns the Windows version code (_WIN32_SERVER_RELEASES in platform.py) and my code should handle every possible case. The minimum version check for Windows Server is set at version 2012, as that's equivalent to desktop version 8 as already present in the code before.

The code for pygame.camera backend detection trips when running on a Server variant of modern Windows, causing initialization of the camera system to fail entirely. This commit expands the Windows version checking code to make sure that both desktop and Server Windows are handled correctly.
Copy link
Member

@illume illume left a comment

Choose a reason for hiding this comment

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

👍 thanks

@illume illume merged commit 9c04fa4 into pygame:main May 15, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants