DXcam icon indicating copy to clipboard operation
DXcam copied to clipboard

Thread issue

Open kavmax opened this issue 2 years ago • 1 comments

I run a simple code:

`import time import dxcam import utils.window as wnd from threading import Thread

window = dxcam.create()

def read_window_frame(window, region=(0, 0, 967, 1047)): image_rgb = None while image_rgb is None: image_rgb = window.grab(region=region)

return image_rgb

def reading(): time.sleep(1) while True: wnd.read_window_frame(window) print("reading frame 2") time.sleep(0.1)

t = Thread(target=reading) t.start()

while True: wnd.read_window_frame(window) print("reading frame 1") time.sleep(0.1) `

it outputs:

reading frame 1
* same ... *
reading frame 1 

Traceback (most recent call last):
  File "G:\PycharmProjects\sky2fly-bot\test.py", line 29, in <module>
reading frame 2
    wnd.read_window_frame(window)
  File "G:\PycharmProjects\sky2fly-bot\utils\window.py", line 20, in read_window_frame
    image_rgb = window.grab(region=region)
  File "G:\PycharmProjects\sky2fly-bot\venv\lib\site-packages\dxcam\dxcam.py", line 70, in grab
    frame = self._grab(region)
  File "G:\PycharmProjects\sky2fly-bot\venv\lib\site-packages\dxcam\dxcam.py", line 81, in _grab
    rect = self._stagesurf.map()
  File "G:\PycharmProjects\sky2fly-bot\venv\lib\site-packages\dxcam\core\stagesurf.py", line 52, in map
    self.texture.QueryInterface(IDXGISurface).Map(ctypes.byref(rect), 1)
_ctypes.COMError: (-2147024882, 'Недостаточно ресурсов памяти для завершения операции.', (None, None, None, 0, None))

reading frame 2
* same ... *
reading frame 2

If I run this code multiple times I get error in different parts of my code (because of using threads). How can I run the same dxcam object without getting this error?

kavmax avatar Jun 19 '22 19:06 kavmax