Skip to content

Commit dfc5a9d

Browse files
Fix pygame.camera backend detection on Windows Server
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.
1 parent 7a1a2c5 commit dfc5a9d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src_py/camera.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,22 @@ def _setup_backend(backend):
125125
def get_backends():
126126
possible_backends = []
127127

128-
if sys.platform == "win32" and int(platform.win32_ver()[0].split(".")[0]) >= 8:
129-
try:
130-
# If cv2 is installed, prefer that on windows.
131-
import cv2
132-
133-
possible_backends.append("OpenCV")
134-
except ImportError:
135-
possible_backends.append("_camera (MSMF)")
128+
if sys.platform == "win32":
129+
version_code = platform.win32_ver()[0].split(".")[0]
130+
if "Server" in version_code:
131+
version_code = ''.join(filter(str.isdigit, version_code))[:4]
132+
minimum_satisfied = int(version_code) >= 2012
133+
else:
134+
minimum_satisfied = int(version_code) >= 8
135+
136+
if minimum_satisfied:
137+
try:
138+
# If cv2 is installed, prefer that on windows.
139+
import cv2
140+
141+
possible_backends.append("OpenCV")
142+
except ImportError:
143+
possible_backends.append("_camera (MSMF)")
136144

137145
if "linux" in sys.platform:
138146
possible_backends.append("_camera (V4L2)")

0 commit comments

Comments
 (0)