Re: [GD-Windows] GetDIBits() return values
Brought to you by:
vexxed72
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 |