Skip to content

Commit

Permalink
Fix pygame.camera backend detection on Windows Server
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrigamerita committed May 3, 2024
1 parent 7a1a2c5 commit dfc5a9d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src_py/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,22 @@ def _setup_backend(backend):
def get_backends():
possible_backends = []

if sys.platform == "win32" and int(platform.win32_ver()[0].split(".")[0]) >= 8:
try:
# If cv2 is installed, prefer that on windows.
import cv2

possible_backends.append("OpenCV")
except ImportError:
possible_backends.append("_camera (MSMF)")
if sys.platform == "win32":
version_code = platform.win32_ver()[0].split(".")[0]
if "Server" in version_code:
version_code = ''.join(filter(str.isdigit, version_code))[:4]
minimum_satisfied = int(version_code) >= 2012
else:
minimum_satisfied = int(version_code) >= 8

if minimum_satisfied:
try:
# If cv2 is installed, prefer that on windows.
import cv2

possible_backends.append("OpenCV")
except ImportError:
possible_backends.append("_camera (MSMF)")

if "linux" in sys.platform:
possible_backends.append("_camera (V4L2)")
Expand Down

0 comments on commit dfc5a9d

Please sign in to comment.