ra1nty / DXcam

A Python high-performance screen capture library for Windows using Desktop Duplication API
MIT License
457 stars 67 forks source link

AttributeError: 'DXCamera' object has no attribute 'is_capturing' #74

Open x64x70 opened 8 months ago

x64x70 commented 8 months ago

So I had working code yesterday. I didn't change a thing. Now suddenly dxcam is throwing this error:

Loading camera...
Traceback (most recent call last):
  File "C:\Users\xxx\PycharmProjects\yolov8\__main__.py", line 96, in <module>
    main()
  File "C:\Users\xxx\PycharmProjects\yolov8\__main__.py", line 84, in main
    camera = load_camera(region)
             ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\PycharmProjects\yolov8\__main__.py", line 56, in load_camera
    camera = dxcam.create(device_idx=0, region=region)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\PycharmProjects\yolov8\venv\Lib\site-packages\dxcam\__init__.py", line 112, in create
    return __factory.create(
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\PycharmProjects\yolov8\venv\Lib\site-packages\dxcam\__init__.py", line 71, in create
    camera = DXCamera(
             ^^^^^^^^^
  File "C:\Users\xxx\PycharmProjects\yolov8\venv\Lib\site-packages\dxcam\dxcam.py", line 33, in __init__
    self._duplicator: Duplicator = Duplicator(
                                   ^^^^^^^^^^^
  File "<string>", line 6, in __init__
  File "C:\Users\xxx\PycharmProjects\yolov8\venv\Lib\site-packages\dxcam\core\duplicator.py", line 19, in __post_init__
    output.output.DuplicateOutput(device.device, ctypes.byref(self.duplicator))
_ctypes.COMError: (-2005270524, 'The specified device interface or feature level is not supported on this system.', (None, None, None, 0, None))
Exception ignored in: <function DXCamera.__del__ at 0x0000022E282677E0>
Traceback (most recent call last):
  File "C:\Users\xxx\PycharmProjects\yolov8\venv\Lib\site-packages\dxcam\dxcam.py", line 243, in __del__
    self.release()
  File "C:\Users\xxx\PycharmProjects\yolov8\venv\Lib\site-packages\dxcam\dxcam.py", line 238, in release
    self.stop()
  File "C:\Users\xxx\PycharmProjects\yolov8\venv\Lib\site-packages\dxcam\dxcam.py", line 138, in stop
    if self.is_capturing:
       ^^^^^^^^^^^^^^^^^
AttributeError: 'DXCamera' object has no attribute 'is_capturing'

I don't understand why this is happening. I don't think it is an issue with my code.

mmayorga97 commented 8 months ago

hey 0xDEITY,

Per the exception: 'The specified device interface or feature level is not supported on this system.'

When creating the instance keep it simple unless you need to, like setting 2 gpu or 2 monitors. In my case, I noticed NOT setting the "device" or "output" helps, and only to define the "region", as code below camera = dxcam.create(region=region) Also you may check if "dxcam.device_info()", "dxcam.output_info()", for more details.

Running this code works if you run it for one or multiple instances in the same scope.


I'm using version 0.0.5 and I'm having the same "is_capturing" issue but with different details related to "available resources", details: output.output.DuplicateOutput(device.device, ctypes.byref(self.duplicator)) _ctypes.COMError: (-2005270494, 'A resource is not available at the time of the call, but may become available later.', (None, None, None, 0, None))

The way I'm able to reproduce this issue is when using multiple instances in different parallel scopes/threads such as SubProcVecEnv, each instance needs a dxcam on a specific region, so on the 3rd or 4th instance created the 'is_capturing' error is thrown, probably by its duplicator nature and resource handling.

My workaround was to provide specific resource time when creating a dxcam instance to avoid all instances creating the cam simultaneously aka "Delayed Start", and at the end releasing properly the instance with ".release" or "del".

ChinaVolvocars commented 1 month ago

I have 2 graphic cards in my computer. I have the same issue with you too. Here is how I solved this problem image image I changed my graphic preference from Nvidia Geforce RTX 3060 to AMD Radeon(TM) Graphics. Then the problem solved. Hope it was helpful to you. Wish you have a nice day~

P.S. Graphics settings -> find python.exe -> Graphic preference -> Power saving

屏幕截图 2024-05-31 222533 屏幕截图 2024-05-31 222612