Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing Exception 1

Status
Not open for further replies.

JurkMonkey

Programmer
Nov 23, 2004
1,731
0
0
CA
This one is strange to me. I'm drawing images at a high rate on a component. I guess this exception occurs when out of memory. Does anyone know how to catch and address this problem, or avoid it in the first place?

Code:
System.ComponentModel.Win32Exception: Not enough storage is available to process this command
   at System.Windows.Forms.DibGraphicsBufferManager.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
   at System.Windows.Forms.DibGraphicsBufferManager.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
   at System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetBounds)
   at System.Windows.Forms.DibGraphicsBufferManager.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetBounds)
   at System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(IntPtr target, Rectangle targetBounds)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 
Got any code to go with that error? Its sorta hard to guess a solution with just an error and a stack trace.
 
After doing some research, there are known issues with the .net 1.1 framework and the graphics classes. A lot of these issues are apparently handled in the 2.0 framework.

On top of that - because an image is considered unmanaged memory, you have to be sure you call .Dispose on the graphics object or else you will have some serious memory leaks.


It seems that a .net app has a 2GB memory limit too... anyone know about this?
 
1. Usually the calls to the methods that handle graphics end in GDI/GDI+. That's why you have to dispose of the graphic objects, in order to release the resources allocated by GDI+.

2. Yes, it is called the /3GB switch (because it is a switcht that you add to boot.ini:
- - - this will allow your application to use 3GB instead of 2; also, this switch applies to 32bit systems only.
 
BOOgyeMan,

I will give you a star. Unfortunately, I keep getting a 404 Error when I click the link to do so.

When it becomes available - it is yours!


I understand that the /3GB switch allows ALL applications to work within the same extra 1GB Virtual Address Space and that it is not dedicated to a single app. This will help though when the user is doing the highly intensive graphics rendering and just needs that extra buffer.

Thanks!
 
If the user is doing highly intensive graphics rendering and 3GB is just not enough there are at least two options:
* Windows Server 2003 Enterprise Edition (with Physical Address Extension)
* 64-bit systems;

The second option seems resonable enough, financially speaking since you're gonna switch to 64bit anyway sooner or later. Just my 0.02€ [tongue]

P.S.: Actually there is another way, quite brutal actually, totally unfit for managed code: allocate non-discardable memory. This way you force windows to page the memory of the other applications that might "steal" some of those 3GB and give you as much as possible of those physical RAM. But it's pretty dirty...
 
Or switch to OpenGL or DirectX and let it do the dirty work for me :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top