Skip to content

Commit a966d54

Browse files
authored
Merge pull request #3633 from Starbuck5/return-of-the-camera
Fix segfault and stub problem with camera module
2 parents 807688e + 0a27537 commit a966d54

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

buildconfig/stubs/pygame/camera.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from pygame.typing import IntPoint
77
def get_backends() -> list[str]: ...
88
def init(backend: str | None = None) -> None: ...
99
def quit() -> None: ...
10-
def list_cameras() -> list[str]: ...
10+
def list_cameras() -> list[str] | list[int]: ...
1111
def colorspace(
1212
surface: Surface, color: Literal["YUV", "HSV"], dest_surface: Surface = ..., /
1313
) -> Surface: ...
@@ -34,7 +34,7 @@ class AbstractCamera(ABC):
3434
class Camera(AbstractCamera):
3535
def __init__(
3636
self,
37-
device: str | int = 0,
37+
device: str | int,
3838
size: IntPoint = (640, 480),
3939
format: str = "RGB",
4040
) -> None: ...

src_c/_camera.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,9 @@ camera_init(pgCameraObject *self, PyObject *arg, PyObject *kwargs)
18861886

18871887
/* needs to be freed with PyMem_Free later */
18881888
dev_name = PyUnicode_AsWideCharString(name_obj, NULL);
1889+
if (dev_name == NULL) {
1890+
return -1;
1891+
}
18891892

18901893
p = windows_device_from_name(dev_name);
18911894

src_py/_camera_opencv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def list_cameras_darwin():
3333

3434

3535
class Camera:
36+
# device should not have a default argument!!
37+
# leaving here for compatibility, but I fixed the stubs.
3638
def __init__(self, device=0, size=(640, 480), mode="RGB"):
3739
self._device_index = device
3840
self._size = size

0 commit comments

Comments
 (0)