AttributeError: _data / "gdi32.GetDIBits() failed" (Windows)
See original GitHub issueGeneral information:
- OS name: Windows
- OS version: 10, version 1803
- OS architecture: 64-bit
- Resolutions:
- Monitor 1: 1920x1080
- Monitor 2: 1920x1080
- Python version: 3.6.5
- MSS version: 3.2.1
Description of the warning/error
MSS consistently throws the following error, always after my program has been running for a little over 3 hours, and after successfully capturing many (22,000+) screenshots in that time.
Full message
== 2018-07-15 07:17:17.953381 runtime: 3:09:39.428722 ==
('gdi32.GetDIBits() failed.', {'bits': 0, 'height': 665, 'width': 1033, 'gdi': <WinDLL 'gdi32', handle 7ffeff9b0000 at 0x1e9c1896898>, 'monitor': {'left': -1034, 'top': 31, 'width': 1033, 'height': 665}, 'self': <mss.windows.MSS object at 0x000001E9C1896860>})
Traceback (most recent call last):
File "D:\IdeaProjects\Python\CaptureTest\main.py", line 98, in <module>
run()
File "D:\IdeaProjects\Python\CaptureTest\main.py", line 82, in run
self.screenshot()
File "D:\IdeaProjects\Python\CaptureTest\main.py", line 77, in screenshot
self.im = self.window.screenshot()
File "D:\IdeaProjects\Python\CaptureTest\main.py", line 84, in screenshot
im = self.mss_instance.grab(area)
File "C:\Users\Nick\AppData\Local\Programs\Python\Python36\lib\site-packages\mss\windows.py", line 202, in grab
del self._data
AttributeError: _data
Other details
I’ve tried to replicate this error by simply calling mss.grab(...)
in a while loop and seeing if it breaks after x number of screenshots, but that runs fine for at least 160,000 iterations, so I can’t figure out why my program consistently seems to break at ~3 hours runtime.
Upon viewing the MSS source, I realised that the del self._data
line is directly followed by raise ScreenShotError('gdi32.GetDIBits() failed.', locals())
, so I suppose my question is:
What could cause gdi32.GetDIBits()
to spontaneously fail?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
AttributeError: _data / "gdi32.GetDIBits() failed" (Windows)
General information: OS name: Windows; OS version: 10, version 1803; OS architecture: 64-bit; Resolutions:.
Read more >GetDIBits failing when trying to save screenshot with ctypes?
I'm attempting to take and save a screenshot using just ctypes . I'm not terrifically familiar with the Windows API, so I've been...
Read more >GetDIBits function (wingdi.h) - Win32 apps - Microsoft Learn
The GetDIBits function retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using the specified ......
Read more >Viewing online file analysis results for 'Setup.exe'
Writes data to a remote process; Fingerprint: Queries kernel debugger information. Queries process information. Queries sensitive IE security settings
Read more >Use takerFree in fMBT With Examples | LambdaTest
... AttributeError: raise NotImplementedError("this windows version does not ... CloseClipboard() raise Exception("error in allocating global memory for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I found the cause.
Redefine
Window.exists()
to free the allocated DC:Another benefit: this will be much faster.
OK, long time since this issue was resolved, but i had time to check for a useful error message. This is was I found: GDI functions do not use
LastError()
, only return0
on error.I followed how ReactOS is doing and this is the revelant parts:
NtGdiGetDIBitsInternal
;GreGetDIBitsInternal
;So, there is no way to get some error message …
Doing this investgation could open a new idea to improve speed on Windows: directly calls
GreGetDIBitsInternal
, if available.