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

Segfault and other problems when initializing a camera without opencv #3022

Open
bilhox opened this issue Jul 27, 2024 · 3 comments
Open

Segfault and other problems when initializing a camera without opencv #3022

bilhox opened this issue Jul 27, 2024 · 3 comments
Labels
bug Not working as intended camera pygame.camera segfault For PRs that fix segfaults or issues containing segfaults which have an higher priority

Comments

@bilhox
Copy link
Contributor

bilhox commented Jul 27, 2024

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 a None 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)
@bilhox bilhox added the bug Not working as intended label Jul 27, 2024
@damusss damusss added segfault For PRs that fix segfaults or issues containing segfaults which have an higher priority camera pygame.camera labels Jul 27, 2024
@Starbuck5
Copy link
Member

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.

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 a None value.

It's doing exactly what the docs says it does. Except IDK what you mean about getting None out of this.

When I don't force opencv backend, I get this error which is not logical :

What's not logical about it? You have to give a device, that's what the docs say.

@bilhox
Copy link
Contributor Author

bilhox commented Jul 28, 2024

What's not logical about it? You have to give a device, that's what the docs say.

Then stubs for the camera constructor are incorrect ? I see a default value for devices and other arguments.

@Starbuck5
Copy link
Member

Yeah looks like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended camera pygame.camera segfault For PRs that fix segfaults or issues containing segfaults which have an higher priority
Projects
None yet
Development

No branches or pull requests

3 participants