Jump to content
  • Advertisement
Sign in to follow this  
Vanz

Problems with "CreateCompatibleBitmap"

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm creating some simple DC's and bitmaps, something like: hdcMap = CreateCompatibleDC(NULL); hMap = CreateCompatibleBitmap(hdc, 1920, 1200); SelectObject(hdcMap, hMap); The other day I noticed that on about my 7th bitmap, it would not create? When I copy to hdc I get just black and using the watch varaibles for this bitmap all the others turn from the value "0xcccccc" to some other value i.e. 0x6b205... etc, yet after defining 6 bitmaps the 7th one turned to "0x000000" and copied just black to the hdc (all this tells me when watching the variable is that it was created to zero result"... Was scratching my head for some time, as the 6 bitmaps before it were all defined the exact same way and worked fine, so I shut down my PC and restarted it, then everything worked fine... but now it's got me wondering what could have caused this?? Why wouldn't it create a bitmap? I though maybe I didn't delete it and it wasn't releasing for some reasone but sure enough I was: DeleteObject (hdcMap); DeleteObject (hMap); Hope that made sense, was a little hard to describe... Thoughts... I like to recreate bugs to make sure I have squashed them properly... rh

Share this post


Link to post
Share on other sites
Advertisement
Obvious problems -

DC's are deleted with DeleteDC, not DeleteObject.

You are not saving the original bitmap after selecting the new one in - you need to select the old bitmap back into the hdc before deleting the hdc or the new bitmap.

You pass "NULL" to CreateCompatibleDC but "hdc" to CreateCompatibleBitmap. You should be passing the same hdc to both. If you need a dc/bitmap compatible with the screen use GetDC(NULL) to retrieve the original hdc. hdc's retrieved with GetDC are released with ReleaseDC, not DeleteDC.

Share this post


Link to post
Share on other sites
Hey thanks Anon Mike, I'll play with these and see if I can recreate the problem...

rh

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!