Re: GetDIBits() return values

Brian Hook <[email protected]> Thu, 5 Jan 2006 00:12:04 -0500
Newsgroups gmane.games.devel.windows
Message-ID <2006150124.970940@GATEWAY>
Found the culprit.

Basically it was a resource exhaustion problem.  My basic font 
rendering was:

SelectObject(hdc, font);
hbm = CreateCompatibleBitmap( hdcDisplay, w, h );
hbmOld=SelectObject(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



-------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_idU5