System.Drawing Exception

  • Thread starter Thread starter Damon Regan
  • Start date Start date
D

Damon Regan

Hello:

I have a Windows application that throws a
NullReferenceException occassionally in one of two ways
when exiting. The application does two activities using
the System.Drawing namespace: 1) It uses a Panel and a
Graphics object as a "test canvas" using
Graphics.MeasureString() to determine how to create
objects and it 2) Draws this collection of objects in a
viewer.

I think the problem lies in the "test canvas" activity
since the viewer exits properly in isolation. I believe
I am disposing of the System.Drawing objects.

The NullReferenceException is being thrown by
system.drawing.dll.

Sometimes the Call Stack looks as follows:

-> system.drawing.dll!
System.Drawing.SafeNativeMethods.GdipDeleteFont
(System.Runtime.InteropServices.HandleRef font =
{System.Runtime.InteropServices.HandleRef}) + 0x2c bytes
system.drawing.dll!System.Drawing.Font.Dispose(bool
disposing = false) + 0x3e bytes
system.drawing.dll!System.Drawing.Font.Finalize() + 0x1e
bytes

The Threads are running as follows:

ID, Name, Location, Priority, Suspend
1988, <No Name>,
Alion.ObjectForum.Diagnostics.EventLog.MonitorThread,
Normal, 0
480, <No Name>, , Normal, 0
1096, .NET SystemEvents,
Microsoft.Win32.SystemEvents.WindowThreadProc, Normal, 0
-> 708, <No Name>,
System.Drawing.SafeNativeMethods.GdipDeleteFont, Highest,
0

The disassembly is as follows:

System.Drawing.SafeNativeMethods.GdipDeleteFont
00000000 push ebp
00000001 mov ebp,esp
00000003 push eax
00000004 push edi
00000005 push esi
00000006 xor edi,edi
00000008 call 000F7DBB
0000000d movzx esi,al
00000010 test esi,esi
00000012 je 0000001E
00000014 xor eax,eax
00000016 pop esi
00000017 pop edi
00000018 mov esp,ebp
0000001a pop ebp
0000001b ret 8
0000001e lea eax,[ebp+8]
00000021 push dword ptr [eax+4]
00000024 push dword ptr [eax]
00000026 call dword ptr ds:[0A9ACB28h]
-> 0000002c mov esi,eax
0000002e mov edi,esi
00000030 mov eax,edi
00000032 pop esi
00000033 pop edi
00000034 mov esp,ebp
00000036 pop ebp
00000037 ret 8

Other times the Call Stack looks as follows:

-> system.drawing.dll!
System.Drawing.SafeNativeMethods.GdipDeleteGraphics
(System.Runtime.InteropServices.HandleRef graphics =
{System.Runtime.InteropServices.HandleRef}) + 0x2d bytes
system.drawing.dll!System.Drawing.Graphics.Dispose(bool
disposing = false) + 0x41 bytes
system.drawing.dll!System.Drawing.Graphics.Finalize() +
0x1e bytes

The Threads are running as follows:

ID, Name, Location, Priority, Suspend
1680, <No Name>,
Alion.ObjectForum.Diagnostics.EventLog.MonitorThread,
Normal, 0
1772, <No Name>,
System.Drawing.SafeNativeMethods.GdipDeleteGraphics,
Highest, 0

The disassembly is as follows:

System.Drawing.SafeNativeMethods.GdipDeleteGraphics

00000000 push ebp
00000001 mov ebp,esp
00000003 push eax
00000004 push edi
00000005 push esi
00000006 xor edi,edi
00000008 call dword ptr ds:[0A8E7160h]
0000000e movzx esi,al
00000011 test esi,esi
00000013 je 0000001F
00000015 xor eax,eax
00000017 pop esi
00000018 pop edi
00000019 mov esp,ebp
0000001b pop ebp
0000001c ret 8
0000001f lea eax,[ebp+8]
00000022 push dword ptr [eax+4]
00000025 push dword ptr [eax]
00000027 call dword ptr ds:[0A8E77ACh]
-> 0000002d mov esi,eax
0000002f mov edi,esi
00000031 mov eax,edi
00000033 pop esi
00000034 pop edi
00000035 mov esp,ebp
00000037 pop ebp
00000038 ret 8


------------------------

Any ideas?

Thanks much,
Damon
 
Back
Top