-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
ScreenShotError: gdi32.GetDIBits() failed. #267
Comments
+1; this issue also happens for me after my program runs for ~3 hours. |
Source mss:
May be: if first cordinate (width, height) == (0, 0); self._handles.data - not set and Error. Need: ?
|
Before changing the current code, we will need a regression test so that we can validate both the issue and the fix. |
mss.exception.ScreenShotError: gdi32.GetDIBits() failed. I get the same error after using 'mss' with 'threading.Timer' for a while. |
@Tratux can you share a minimal reproduction code please? |
@BoboTiG I've tested and I got the same error with this code. The code executed for at least 10 min without an error.
|
@Tratux If run in Python 3.12
If run in 3.11
For fast: threading.Timer(0.001, loopFunc) Im run Process Explorer: and saw after GDI handles ~ 10K python.exe crash. This Windows limit GDI handles. Also in my Windows Event Viewer: Windows Logs->Application |
The Tratux error is not the same as the original error. For first issue :
Same error:
|
I'm seeing the same error message here, mss.exception.ScreenShotError: gdi32.GetDiBits() failed. It was working fine for a few hours and then stopped. Here is the relevant code.
|
General information:
Description of the warning/error
I packaged my project as an exe using pyinstaller and ran it. At some point on the 6th day, I reported a ScreenShotError error when taking a screenshot, and an AttributeError error occurred in subsequent screenshots.
Full message
Other details
First of all, thank you very much for providing a high-performance screenshot tool, I like it very much!
The following is a detailed description and part of the code for the problem I encountered.
I used pynput.mouse to monitor the mouse. When the mouse is left-clicked on the specified area in the program window I specified, I will take a screenshot and save some other additional coordinate information. Then I used pyinstaller to package my project as an exe and run it, but after about 6 days of running it threw a ScreenShotError at some point, and all subsequent clicks would throw an exception AttributeError: _data, and subsequently I obtained the system zoom and foreground window coordinates. , the xy value passed by pynput will become 0 !
I checked the relevant issues and seemed to not find a solution to the problem related to me. Then I tried to read your source code and found that the location where the exception was thrown was in mss/windows. py:252:
it judged bits != height. I checked my logs. When the last error was reported, the monitor parameter I passed was correct: (3, 22, 794, 629)
so it can only be the value of bits has a problem. But sorry, I don't know much about win32api, so I went to Microsoft's official website to check the relevant documents and roughly understood the role of BitBlt/GetDIBits/GetWindowDC. I guess the root cause may be that an invalid handle was obtained when windows.py:112 was initialized causing this error:
I briefly checked the code of pynput.mouse and learned that it is a single-thread processing callback function, which means that the first time this error occurred in its internal sub-thread, it affected all my subsequent code that calls win32api, just like this:
Of course, the above It's just my speculation based on the documentation and source code. I hope you can reply. Thank you again!
How I get Win10 Scaling
mouse_monitor.py simplified example
How I get foreground window rect
Upvote & Fund
The text was updated successfully, but these errors were encountered: