|
-
June 13th, 2012, 01:15 PM
#16
Re: CreateCompatibleBitmap failed
 Originally Posted by Ralf Schneider
Hello Paul,
of course, I do believe you.
But that do not help me....
Perhaps you should just go on the assumption that that's the problem and check that you're releasing all your GDI objects when you're done with them.
-
June 13th, 2012, 01:58 PM
#17
Re: CreateCompatibleBitmap failed
 Originally Posted by Ralf Schneider
I has to restart the app many times. No problem half of the day.
 Originally Posted by Alex F
Possibly your program leaks resources. Check this with Task Manager.
Even if the app leaks any, restarting the app unconditionally releases the ones. There must be something else.
Last edited by Igor Vartanov; June 13th, 2012 at 02:00 PM.
Best regards,
Igor
-
June 13th, 2012, 02:26 PM
#18
Re: CreateCompatibleBitmap failed
 Originally Posted by Ralf Schneider
Hello Paul,
of course, I do believe you.
But that do not help me....
Processes tab -> Options -> Select Columns
Do you now see this option?
Regards,
Paul McKenzie
Last edited by Paul McKenzie; June 13th, 2012 at 02:30 PM.
-
June 13th, 2012, 05:48 PM
#19
Re: CreateCompatibleBitmap failed
more likely than not, your compatible bitmap will be 4bytes per pixel instead of the 3 you're assuming. Thus resulting in a 67Mb bitmap.
Countrary to your first post, this memory is not usually allocated in videomemory but in regular systemmemory.
It is entirely possible that while you have enough free memory still available, you no longer have a continguous block of that size available, causing the function to fail.
If you must allocate large chunks of memory it is recommended you either allocate these as early in your program as possible to minimize effects of memory fragmentation.
Alternatively, you could also reserve a large chunk of memory up front and do your own managing of the block of memory.
If you only need to make a bitmap once, and it's size will never change. Make it as early as you possibly can, and try not to destroy/recreate it.
Remember also that the bitmap is allocated by the OS. If you have previously allocated a lot of your own memory via new/malloc, that memory is still reserved for use by your applications heap and isn't available for the OS even if it has a sufficiently large enough chunk of free memory.
Alternatively build your app as a 64bit app, large memory block exhaustion by fragmentation is almost nonexistant in Win64. (or you're making some pretty funky programs )
Last edited by OReubens; June 13th, 2012 at 05:53 PM.
-
June 13th, 2012, 11:59 PM
#20
Re: CreateCompatibleBitmap failed
Well, you need to find some program with such functionality, or install another Windows version. Maybe Home edition doesn't support this, and Professional does. You can install another Windows version as virtual computer, for example, using free VirtualBox.
I would ask in different forums about programming tools, that can provide such information about running process. For example, try Process Explorer: http://technet.microsoft.com/en-us/s...rnals/bb896653 I am not sure that it shows all required counters, anyway, you need a tool like this.
-
June 14th, 2012, 01:29 AM
#21
Re: CreateCompatibleBitmap failed
Hello,
thx for all the hints.
The following I forgot to say:
after failure of
------------
CBitmap bm;
CClientDC dc(NULL);
bm.CreateCompatibleBitmap(&dc,4096,4096);
-----------
I use 2048 instead of 4096. I never had a problem with this.
But this size is too small. But it helps me not to reboot always.
May this information helps to find the cause of my problem....
Ralf
-
June 14th, 2012, 02:00 AM
#22
Re: CreateCompatibleBitmap failed
Okay, why don't you try to create it only once and reuse during your paints?
Best regards,
Igor
-
June 14th, 2012, 02:32 AM
#23
Re: CreateCompatibleBitmap failed
Hello Igor, and @all
I create it only once in the app.
But not at the beginning.
I create it at the time I need it. Then do my drawings and delete the bitmap.
Then the released memory can be used for other stuff.
I do not know, if it is a good idea to allocate the memory for the bitmap at the beginning. In this case I reserve memory that can not used for other things until it is really needed for the bitmap drawings.
I think, the basic thing for me at the moment is to know, what cause the CreateCompatibleBitmap-function to fail with 4096 (and not with 2048).
Could this be handles, that are not available. Or it is video memory or is it heap memory or fragmented memory.
Any idea to get the answer?
I think, handles are not the problem?
thx.
Ralf
-
June 14th, 2012, 02:47 AM
#24
Re: CreateCompatibleBitmap failed
update:
I think, CreateCompatibleBitmap uses video memory:
I uses Process explorer (linked above) to check the memory consumption.
And there is no changes in the amount of "physical memory - working set" for and after the CreateCompatibleBitmap call.
What can I do?
Ralf
-
June 14th, 2012, 03:31 AM
#25
Re: CreateCompatibleBitmap failed
 Originally Posted by Ralf Schneider
Hello Igor, and @all
I create it only once in the app.
But not at the beginning.
I guess I will have to be the one to say this:
We don't know what your app is really doing. You just saying what it does is not enough information.
There have been many posts by persons who claim "I'm doing this and doing that", and when it comes time to actually see the code, they are not doing what they say they're doing, or at the very least, they're doing things incorrectly.
Sorry to be harsh, but unless we see actual code (not just three lines), we have no way to verify what you're saying is true. We could be ending up on a wild goose chase, when all that really is a problem is a bug in your program you haven't diagnosed.
If the problem is really those 3 lines you are posting, why not create a very simple, Win32 or MFC application that performs those operations correctly without any sign whatsoever of memory/GDI leakage of handles? You don't even need to draw anything -- just create a simple app that calls those functions in a correct, consistent manner.
That is what any programmer would do at this stage. If it is a video card/memory issue, then the simple application would show the very same issue. If it shows the same issue, then post that project here. This is much better then guessing what is the problem.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; June 14th, 2012 at 03:41 AM.
-
June 14th, 2012, 04:06 AM
#26
Re: CreateCompatibleBitmap failed
Note that I did say that memory for createcompatiblebitmap is not usually allocated in videomemory, there are some specific cases where this IS indeed happening in the videomemory. If your test for memory consumtion is done right, it may indeed indicate you have one of those cases where memory is being reserved on the videocard.
Windows does this in specific cases to allow the video accellerator to do it's magical stuff. That also means that memory allocated in this way must fit into the videocards memory and must also deal with all the nasties associated with it.
Allocating 67Mb on your videocard is a big deal. You already are using some of it for what you actually see on screen. Windows is already using some of it to cache important and frequently used system resources. The glass effect used in Vista/7 among others is a done with a bitmap stored in videomemory.
Thumbnails in the taskbar also temporarily use videomemory. Those things use, and eventuelly fragment to some degree the available memory for additional allocations.
Long story short, if you need a bitmap as large as 4k by 4k in truecolor... You really should be using DIB's instead of DDB's.
Have a look at CreateDIBSection() instead.
-
June 14th, 2012, 04:18 AM
#27
Re: CreateCompatibleBitmap failed
Hello OReubens,
I tried to use CreateDIBSection also.
But there were also some problems.
AFAI remember a DIBSection can not be selected into the DC (SelectObject works not for DIBs) and then a drawing into the dib is not possible.
See my attempt:
http://forums.codeguru.com/showthread.php?t=523980
Ralf
-
June 14th, 2012, 04:30 AM
#28
Re: CreateCompatibleBitmap failed
 Originally Posted by Ralf Schneider
Hello OReubens,
I tried to use CreateDIBSection also.
But there were also some problems.
AFAI remember a DIBSection can not be selected into the DC (SelectObject works not for DIBs) and then a drawing into the dib is not possible.
See my attempt:
http://forums.codeguru.com/showthread.php?t=523980
Ralf
Even that link demonstrated you're doing things incorrectly.
The best bet is for you to create a simple application as I stated that shows the error. Posting 3 line snippets as you're doing in this thread, or faulty code as you are doing in the thread above, doesn't get closer into finding out exactly what you're doing.
Regards,
Paul McKenzie
-
June 14th, 2012, 04:58 AM
#29
Re: CreateCompatibleBitmap failed
 Originally Posted by Paul McKenzie
Even that link demonstrated you're doing things incorrectly.
Hello Paul,
I know, that you want to help me. Please tell me, are you familiar with the DIBSection stuff?
AFAIK: the link demonstrates that the approach with the DIBSection do not work. Because there is not Bitmap selected into the DC. And this leads to an access violation.
Ralf
-
June 14th, 2012, 06:52 AM
#30
Re: CreateCompatibleBitmap failed
 Originally Posted by Ralf Schneider
AFAIK: the link demonstrates that the approach with the DIBSection do not work. Because there is not Bitmap selected into the DC. And this leads to an access violation.
DIB actually can be selected into DC alright. But its attributes should comply with the manner of drawing/blitting to DC. For example, in case map mode is MM_TEXT, the DIB should be top-down DIB. 
Besides, the DC should be properly freed. I met a remark that using ReleaseDC instead of DeleteDC can cause an access violation.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|