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

ThreadSafety: gdi32.GetDIBits() failed #198

Closed
anawkward opened this issue Dec 30, 2020 · 3 comments · Fixed by #250
Closed

ThreadSafety: gdi32.GetDIBits() failed #198

anawkward opened this issue Dec 30, 2020 · 3 comments · Fixed by #250
Labels

Comments

@anawkward
Copy link

anawkward commented Dec 30, 2020

General information:

  • OS name: windows7
  • OS version: sid
  • OS architecture: 64 bits
  • Resolutions:
    • Monitor 1: 1900x1200
    • Monitor 2: 1900x1200
  • Python version: 3.7.3
  • MSS version: 6.1.0

Description of the warning/error

import threading
import mss
import time

region1 = (0,0,1900,1200)
region2 = (0,0,100,100)

# A) make a grabbing thread

class a_thread(threading.Thread):
    def run(self):
        sct = mss.mss()
        while True:
            sct.grab(region1)
            time.sleep(1)


t = a_thread()
t.start()

time.sleep(1)

# B) grab

sct = mss.mss()
x = sct.grab(monitor=region2)

# the codes above gives an {ScreenShotError("gdi32.GetDIBits() failed.")} Exception.

Full message

Exception in thread Thread-8:
Traceback (most recent call last):
File "C:\Anaconda3\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "", line 12, in run
File "C:\Anaconda3\lib\site-packages\mss\base.py", line 88, in grab
return self._grab_impl(monitor)
File "C:\Anaconda3\lib\site-packages\mss\windows.py", line 285, in _grab_impl
raise ScreenShotError("gdi32.GetDIBits() failed.")
mss.exception.ScreenShotError: gdi32.GetDIBits() failed.

Other details

I think the error is related with the thread safety of mss.mss(). I did some A/B tests to reproduce it.

  1. when region1 = region2, it was okay. error didn't appear.
  2. when (B) is done before (A), like (B) -> (A) -> (B), it was okay. no error appeared.

I guess the cause is somewhere around the initialization of mss.mss() and a grab() method does something on the initialization.
I hope this issue helps to improve thread safety. contact me for any further information if needed.

@BoboTiG
Copy link
Owner

BoboTiG commented Jul 15, 2022

@anawkward would you be able to retry with changes from #211?

@FlorinPT
Copy link

@anawkward can you help me

@CTPaHHuK-HEbA
Copy link
Contributor

@FlorinPT Check closed issue #212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants