none
GDI+ Error and (JIT) debugging message, help need

    Question

  • Below is the error message, anyone here know what the problem cause this error? how to fix it?


    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.OutOfMemoryException: Out of memory.
    at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
    at System.Windows.Forms.MenuItem.WmDrawItem(Message& m)
    at System.Windows.Forms.Control.WmDrawItemMenuItem(Message& m)
    at System.Windows.Forms.Control.WmDrawItem(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ToolBar.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)

    Sunday, February 20, 2005 9:26 PM

Answers

  • Yes, this is a known issue and there isn't a simple workaround for it.

    Pawel, the information you provided is very much appreciated.

    Thursday, December 15, 2005 12:46 AM

All replies

  •  WinFormsUser wrote:
    Below is the error message, anyone here know what the problem cause this error? how to fix it?


    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.OutOfMemoryException: Out of memory.
       at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
       at System.Windows.Forms.MenuItem.WmDrawItem(Message& m)
       at System.Windows.Forms.Control.WmDrawItemMenuItem(Message& m)
       at System.Windows.Forms.Control.WmDrawItem(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ToolBar.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)



    I am facing similar problem and guess its probably because of latest hotfix applied which suppose to fix some image processing vulnerabilities in Windows but has actually broken up the .net framework's graphic rendering and image processing modules.

    Please can anyone help us?
    Saturday, November 19, 2005 6:04 AM
  • Hello,

    I'm facing the same problem in big ERP aplication written in C#

    ************** Exception Text **************
    System.OutOfMemoryException: Out of memory.
       at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
       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.ScrollableControl.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)
    ************** Exception Text **************

    Does anyone knows how to solve this problem?
    Tuesday, November 29, 2005 9:20 AM
  • Hi all!

    It would be great if each of you could report your issue to Microsoft http://lab.msdn.microsoft.com/productfeedback/default.aspx

    It is very important to us to understand what the application is doing when this happens, so add as much information about your app as possible.  Here some of the information we would like to see:

    - Number of threads and painting threads your process run.
    - Number of processes running in the system.
    - Number of GDI and User objects allocated (can be obtained from Task Manager) by your process and by the entire system.
    - System characteristics (dual proc? available and total memory, proc speed, OS)
    - Does this happen at design time (Visual Studio) and/or at runtime?
    - A brief description of what the application does and what controls it uses.

    thanks in advance,

    Tuesday, November 29, 2005 7:38 PM
  • I’m glad that someone from Microsoft is interested in correcting this error because I’m almost sure the problem is in .NET Framework/GDI+.

    The main problem is that this error is nondeterministic.

    It is related to following GDI+ error:
    System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
       at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
       …
       at System.Windows.Forms.MenuItem.WmDrawItem(Message& m)
       at System.Windows.Forms.Control.WmDrawItemMenuItem(Message& m)
       at System.Windows.Forms.Control.WmDrawItem(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at Teta.Sumo.Runtime.FrmMainForm.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)

    Google says: “write double buffering manually to avoid the error above”
    OK, but when you write double buffering you will get sooner or later OutOfMemoryException in your App…

    HOW TO GENERATE ERROR?
    I’m responsible for removing memory leaks , GDI objects leaks, USER object leaks in our application (it is large system written by 20 programmers in VS.NET 2003 in windows forms with many user controls and graphics). The “OutOfMemoryException” is the very last error I’m fighting with in our app. It is very hard to isolate this error.
    It is not related with lack of memory.
    It is not related with lack of GDI objects.
    It is not related with lack of USER objects.
    It is not appearing on each computer: more likely appear on computers with poor build-in graphics cards. Amount of free RAM is not important, I have 800MB free of RAM and I get very quickly OutOfMemoryException exception)
    Some times you need to use the application whole day to get this error.
    The simplest way to generate it I found is:
    - prepare owner draw menu based on MainMenu: mainMenuItem_DrawItem, mainMenuItem_MeasureItem with complicated painting.
    - Run application and resize it for at least 5 minutes !!
    If your painting use double buffering you get OutOfMemoryException.
    If your painting do not use double buffering you get generic GDI+ error.

    Best Regards,
    Pawel

    Wednesday, November 30, 2005 8:28 AM
  • Hi Pawel, Im facing the same problem now, I mean the GDI+ error. I want to know, whether you have solved this issue. If so, please can u lend some help, how it could be solved.

    Thanks in Advance
    Gopinath Ramamoorthy.

    Thursday, December 08, 2005 12:36 PM
  • Hello Gopinath,

    Unfortunately I still can't solve completely this problem!
    The only workaround I know is manual double buffering:

    Create a temporary in-memory image,
    obtain a Graphics object for the temporary image, and draw temporary on the screen.

    MORE DETAILS HERE:
    http://www.bobpowell.net/imagefileconvert.htm

    I also found following Microsoft answer to this problem:

    ------------------------
    This appears to be a known issue that will be addressed by future service
    pack. Until that time I'm afraid there isn't a known workaround. If you'd
    like us to investigate it further you can open up a support incident and we
    can ensure that you are indeed experiencing a known issue or if something
    in your code is causing this.

    Thanks! Robert Gruen
    Microsoft, VB.NET
    ------------------------
    Source:
    http://dotnet247.com/247reference/msgs/37/185052.aspx
    Thursday, December 08, 2005 1:08 PM
  • Yes, this is a known issue and there isn't a simple workaround for it.

    Pawel, the information you provided is very much appreciated.

    Thursday, December 15, 2005 12:46 AM
  •  

    I totally missed this message. Don't forgot to put it as a question instead of a comment!

    The thing I can add about this is that GDI+ tends to throw OutOfMemoryException when something else is going on. I've seen people complaining about this in the newsgroups and elsewhere on the internet. I believe these are generally ArgumentExceptions that are thrown as OutOfMemoryExceptions. I see that someone from Microsoft already responded to this thread, so I fear it is not easily fixed, but it may be a good thing to keep in mind.

    Maybe Gopinath's OutOfMemoryException is simply an ArgumentException. I would check if I were you.

    Friday, December 16, 2005 7:10 PM
  • Hi

    Can anybody post a code snippet ,How to achieve DoubleBuffering? Actually I dont know the difference between them.

    thanks in advance

    Friday, March 31, 2006 1:24 PM
  • We have found that this issue can be originated when a Graphics object is finalized instead of explicitly disposed.  GDI reuses HDCs and only one thread can use an HDC at a time; it is possible that during finalization the Graphics object locks its HDC when it has already been deleted and reused by the double-buffering Graphics object making the latter fail.

    Bottom line: make sure you explicitly dispose *all* your Graphics objects.

    Friday, March 31, 2006 5:07 PM
  • Bottom line: make sure you explicitly dispose *all* your Graphics objects.

    Is that documented somewhere other than here?


    Sam Hobbs; see my SimpleSamples.Info
    Tuesday, July 20, 2010 7:41 PM