-
-
Notifications
You must be signed in to change notification settings - Fork 193
Open
Labels
bugNot working as intendedNot working as intendedcamerapygame.camerapygame.camerasegfaultFor PRs that fix segfaults or issues containing segfaults which have an higher priorityFor PRs that fix segfaults or issues containing segfaults which have an higher priority
Description
Environment:
pygame-ce 2.5.1.dev1 (SDL 2.30.5, Python 3.12.0)
Platform: Windows-11-10.0.22631-SP0
System: Windows
System Version: 10.0.22631
Processor: AMD64 Family 23 Model 104 Stepping 1, AuthenticAMD SSE2: Yes AVX2: Yes NEON: No
Architecture: Bits: 64bit Linkage: WindowsPE
Python: CPython 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
pygame version: 2.5.1.dev1
SDL versions: Linked: 2.30.5 Compiled: 2.30.5
SDL Mixer versions: Linked: 2.8.0 Compiled: 2.8.0
SDL Font versions: Linked: 2.22.0 Compiled: 2.22.0
SDL Image versions: Linked: 2.8.2 Compiled: 2.8.2
Freetype versions: Linked: 2.11.1 Compiled: 2.11.1
Display Driver: windows
Mixer Driver: Mixer Not Initialized
Current behavior:
Imagining you don't have opencv-python
installed, and you don't force OpenCV
backend with environment variables , you get a segfault when initialising a camera object.
Expected behavior:
No segfault, and a descriptive message of what is actually hapenning.
Test code
import pygame
import os
import pygame.camera
# os.environ["PYGAME_CAMERA"] = "opencv"
screen = pygame.display.set_mode([512, 512])
pygame.print_debug_info()
pygame.camera.init()
print(pygame.camera.list_cameras())
camera = pygame.camera.Camera(0)
camera.start()
version = True
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
screen.blit(camera.get_image())
pygame.display.flip()
Other things to mention :
- It would be interesting to tell in the wiki for compilation from source for Windows, how to get access to
pygame.camera
, by explaining how to compile with MSVC. pygame.camera.list_cameras()
is broken, sometimes it returns you a list of string (when I don't force opencv backend), sometimes a list of one integer (when I force opencv backend) and ultimately aNone
value.- When I don't force
opencv
backend, I get this error which is not logical :
Traceback (most recent call last):
File "\\wsl.localhost\Ubuntu-24.04\home\rakoon\pygame-ce\a.py", line 13, in <module>
camera = pygame.camera.Camera()
^^^^^^^^^^^^^^^^^^^^^^
TypeError: function takes at least 1 argument (0 given)
Metadata
Metadata
Assignees
Labels
bugNot working as intendedNot working as intendedcamerapygame.camerapygame.camerasegfaultFor PRs that fix segfaults or issues containing segfaults which have an higher priorityFor PRs that fix segfaults or issues containing segfaults which have an higher priority
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Starbuck5 commentedon Jul 28, 2024
As discussed on discord, this an incorrect use of the API.
camera.list_cameras() gives you a list of things that can be passed into Camera() as the device name, you're not honoring that here, you're passing in something random that list_cameras did not give you. That being said it shouldn't segfault either.
It's doing exactly what the docs says it does. Except IDK what you mean about getting None out of this.
What's not logical about it? You have to give a device, that's what the docs say.
bilhox commentedon Jul 28, 2024
Then stubs for the camera constructor are incorrect ? I see a default value for devices and other arguments.
Starbuck5 commentedon Jul 28, 2024
Yeah looks like it.