Thread: [GD-Windows] GetDIBits() return values
Brought to you by:
vexxed72
From: Brian H. <ho...@bo...> - 2006-01-04 22:41:54
|
On occasion GetDIBits() returns 0, indicating failure, but GetLastError() returns 0, indicating success. The dimensions I pass in are scan start=3D0,scanlines=3D12. Everything seems to work fine, but very occasionally (< 1% of the time) I get a return value that !=3D 12. Anyone know under what conditions this might happen? Thanks, Brian |
From: Bryan W. <br...@xm...> - 2006-01-05 01:29:38
|
Are you absolutely positive you don't call anything that sets the = Windows error before you read it? I spent a few days trying to figure out why a certain bit of code always logged windows error 2, but I couldn't get an error when run in the debugger. After a while, I realized that the logging macros were = resetting the error code to either 0 or 2. The error 2 came from trying to write = to the debugger when it wasn't attached. Just something to look for. Bryan. -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of = Brian Hook Sent: Wednesday, January 04, 2006 3:42 PM To: gam...@li... Subject: [GD-Windows] GetDIBits() return values On occasion GetDIBits() returns 0, indicating failure, but=20 GetLastError() returns 0, indicating success. The dimensions I pass=20 in are scan start=3D0,scanlines=3D12. Everything seems to work fine, = but=20 very occasionally (< 1% of the time) I get a return value that !=3D 12. Anyone know under what conditions this might happen? Thanks, Brian ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log = files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_idv37&alloc_id=16865&op=3Dick _______________________________________________ Gamedevlists-windows mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows Archives: http://sourceforge.net/mailarchive/forum.php?forum_idU5 |
From: Brian H. <ho...@bo...> - 2006-01-05 02:50:35
|
On Wed, 4 Jan 2006 18:29:22 -0700, Bryan Wagstaff wrote: > Are you absolutely positive you don't call anything that sets the > Windows error before you read it? Yeah, very next line is the check and report. This one is mystifying me, leading me to think it's a memory corruption issue because it only happens about 1% of the time using the exact same inputs. Brian |
From: Dan T. <da...@ar...> - 2006-01-05 03:13:42
|
Any possibility of threading issues? If you add a second call to GetDIBits right after (i.e. on skitzo fail, try agian), does it work or fail again? Maybe toss a Sleep(1) between the two? If the second one fails, you might be able to disasm into gdi and see whats up. Could try VirtualAllocing the memory and protect it vs Write on the second call, see if it even touches the memory. All I got. -Dan Brian Hook wrote: >On Wed, 4 Jan 2006 18:29:22 -0700, Bryan Wagstaff wrote: > > >>Are you absolutely positive you don't call anything that sets the >>Windows error before you read it? >> >> > >Yeah, very next line is the check and report. This one is mystifying >me, leading me to think it's a memory corruption issue because it only >happens about 1% of the time using the exact same inputs. > >Brian > > > >------------------------------------------------------- >This SF.net email is sponsored by: Splunk Inc. Do you grep through log files >for problems? Stop! Download the new AJAX search engine that makes >searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! >http://ads.osdn.com/?ad_idv37&alloc_id865&op=click >_______________________________________________ >Gamedevlists-windows mailing list >Gam...@li... >https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows >Archives: >http://sourceforge.net/mailarchive/forum.php?forum_idU5 > > > > |
From: Brian H. <ho...@bo...> - 2006-01-05 03:28:44
|
On Wed, 04 Jan 2006 19:14:36 -0800, Dan Thompson wrote: > Any possibility of threading issues? Doubtful -- it's a Python installation and this is just a simple extension for it, no multithreading. > If the second one fails, you might be able to disasm into gdi and > see whats up. Could try VirtualAllocing the memory and protect it > vs Write on the second call, see if it even touches the memory. I'm not quite that hardcore =3D) Brian |
From: Brian H. <ho...@bo...> - 2006-01-05 05:12:19
|
Found the culprit. Basically it was a resource exhaustion problem. My basic font rendering was: SelectObject(hdc, font); hbm =3D CreateCompatibleBitmap( hdcDisplay, w, h ); hbmOld=3DSelectObject(hdc,hbm); TextOut(hdc, 0, 0, buf, strlen(buf)); SelectObject(hdc,hbmOld); GetDIBBits( ... ); //get BMI info GetDIBBits( ... ); //get actual data free( bits ); free( bmi ); SelectObject( hdc, hfontOld ); The font in use is retained across calls, as is the DC I created (using CreateCompatibleDC()). So this function basically just selects a font into the DC, creates a bitmap, selects the bitmap, renders text, deselects the bitmap, grabs the bits, frees them, unselects the font. The problem was that I was forgetting to call DeleteObject( hbm ) -- I was creating a new bitmap every time the function was called, which is why it was happening that "1% of times" -- it took probably a few hundred calls (at like 20 calls/second) for it to manifest. My guess is that HBITMAPs were exhausted or something (these were pretty small bitmaps, probably 8K or so each), but instead of dying on me and reporting an error where you'd expect, it actually died on me inside GetDIBBits() after I received a valid HBITMAP. The NEXT time through it would then die on CreateCompatibleBitmap(), so I'm assuming that some kind of resource acquisition/lock was failing inside of GetDIBBits() that was failing even though I had a valid HBITMAP. Adding DeleteObject() made the problem go away, so I'm a happy programmer (for now). Still not sure why GetLastError() wasn't reporting anything, but oh well. Brian |