Need help. Having trouble locating GDI+ exception in Windows Forms.

K

Ken Varn

I have a multi-threaded managed MFC C++ application that is using GDI+
through .NET.

I am loading successive JPEGs into a Bitmap object in one thread and
displaying them into a Windows Forms PictureBox control in another thread.
Mutexs have been put in place to protect the Bitmap object and PictureBox
from possible collision. However, I occasionally getting an unhandled
Windows Forms exception that I cannot seem to locate and it is baffling me
because the stack trace does not show any of my code layers. This exception
is highly unpredictable, and ususally occurs when the application is run for
the first time (Maybe before the IL is converted to native by JIT).

The exception is below. I am hoping that someone might see something
familiar here and could explain why this is happenning. Note that the
managed C++ application also has a main native MFC dialog window that
displays a managed .NET forms window.

The exception dump is as follows:

************** Exception Text **************
System.InvalidOperationException: The object is currently in use elsewhere.
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at
System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer
buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
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)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
LogFile
Assembly Version: 0.0.0.0
Win32 Version: 1, 0, 0, 1
CodeBase: file:///C:/dvr/LogFile.dll
----------------------------------------
DVR
Assembly Version: 0.0.0.0
Win32 Version: 2.0.0.0
CodeBase: file:///C:/dvr/dvr.exe
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
FrameGrabber
Assembly Version: 0.0.0.0
Win32 Version: 1.0.0.1
CodeBase: file:///C:/dvr/FrameGrabber.DLL
----------------------------------------
Microsoft.VisualC
Assembly Version: 7.0.5000.0
Win32 Version: 7.10.3052.4
CodeBase:
file:///c:/winnt/assembly/gac/microsoft.visualc/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualc.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Data
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------
GDIPlusEx
Assembly Version: 1.0.1495.16797
Win32 Version: 1.0.1495.16797
CodeBase: file:///C:/dvr/GDIPlusEx.DLL
----------------------------------------
System.Runtime.Remoting
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.runtime.remoting/1.0.5000.0__b77a5c561934e089/system.runtime.remoting.dll
----------------------------------------
DVRGUI
Assembly Version: 1.0.1495.16885
Win32 Version: 1.0.1495.16885
CodeBase: file:///C:/dvr/DVRGUI.DLL
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.




--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
K

Ken Varn

I have protected just about everything I can think of. The strange thing is
that the stack trace does not show any references to my code.
I am wondering if the problem lies in a low level paint call in the
PictureBox object. If I select continue on the exception dialog, the
PictureBox object will sometimes contain a red X in it. I have even tried
to put try/catch around the OnPaint call in my form, but the
exception still gets through occasionally. It is almost always reported
when the form is being displayed for the first time.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Bob Powell said:
I'm sorry but I don't know the specific answer to this one but I have
noticed that a lot of multithreaded applications fail with this kind of
error. Maybe you haven't been paranoid enough with your mutexes.

--
Bob Powell [MVP]
C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

Ken Varn said:
I have a multi-threaded managed MFC C++ application that is using GDI+
through .NET.

I am loading successive JPEGs into a Bitmap object in one thread and
displaying them into a Windows Forms PictureBox control in another thread.
Mutexs have been put in place to protect the Bitmap object and PictureBox
from possible collision. However, I occasionally getting an unhandled
Windows Forms exception that I cannot seem to locate and it is baffling me
because the stack trace does not show any of my code layers. This exception
is highly unpredictable, and ususally occurs when the application is run for
the first time (Maybe before the IL is converted to native by JIT).

The exception is below. I am hoping that someone might see something
familiar here and could explain why this is happenning. Note that the
managed C++ application also has a main native MFC dialog window that
displays a managed .NET forms window.

The exception dump is as follows:

************** Exception Text **************
System.InvalidOperationException: The object is currently in use elsewhere.
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at
System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer
buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
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)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
LogFile
Assembly Version: 0.0.0.0
Win32 Version: 1, 0, 0, 1
CodeBase: file:///C:/dvr/LogFile.dll
----------------------------------------
DVR
Assembly Version: 0.0.0.0
Win32 Version: 2.0.0.0
CodeBase: file:///C:/dvr/dvr.exe
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
FrameGrabber
Assembly Version: 0.0.0.0
Win32 Version: 1.0.0.1
CodeBase: file:///C:/dvr/FrameGrabber.DLL
----------------------------------------
Microsoft.VisualC
Assembly Version: 7.0.5000.0
Win32 Version: 7.10.3052.4
CodeBase:
file:///c:/winnt/assembly/gac/microsoft.visualc/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualc.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Data
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------
GDIPlusEx
Assembly Version: 1.0.1495.16797
Win32 Version: 1.0.1495.16797
CodeBase: file:///C:/dvr/GDIPlusEx.DLL
----------------------------------------
System.Runtime.Remoting
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.runtime.remoting/1.0.5000.0__b77a5c561934e089/system.runtime.remoting.dll
----------------------------------------
DVRGUI
Assembly Version: 1.0.1495.16885
Win32 Version: 1.0.1495.16885
CodeBase: file:///C:/dvr/DVRGUI.DLL
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top