NullReference error in DrawMapWPF()

Topics: Help
Nov 21, 2011 at 2:26 PM

I've just started using GMap, and I have a big problem with this error.

I've downloaded and installed change set c0108a299258. The demo compiles and runs perfectly fine, but when I implement in my own project, this is when it fails. 

In my window, the xaml entry for the map is:

<src:Map Grid.Row="1" Grid.Column="2" x:Name="MainMap" Zoom="13" MaxZoom="17" MinZoom="1"  />

and the codebehind in my Window_Loaded() is:

MainMap.MapProvider = GMapProviders.OpenStreetMap;
MainMap.Position = new PointLatLng(51.93, -1.43);
MainMap.Zoom = 9;

When the program runs, the map opens and is displayed correctly. But after about 1 second the error happens and the debugger stops in GMapControl.cs, on the line

Core.tileDrawingListLock.AcquireReaderLock();

Indeed tileDrawingListLock is null.

My system is Win7, and the target is .Net 4.0. The downloaded zip was unblocked before installing. I'm sure it is some setting or file that didn't transfer across from the demo correctly, but I can't figure what. Any ideas?

Thanks
Tim 

Nov 21, 2011 at 2:40 PM

i'm sure you use latest/unstable code, and thats what you get, use latest release changeset it works fine, or if you have time help me fix it ;}

...can you share your demo source?

Nov 21, 2011 at 2:59 PM

It's more likely to be something I've missed - a wrong library version or similar - than a bug in the code, since the demo runs fine.

I've found the reason tileDrawingListLock is null is because GMapControl_Unloaded gets called. The stack trace doesn't go further back so I don't know why it's being called yet.


The project I've put it in is an existing program, where it's replacing (hopefully) a google maps browser control. The project is about 160MB. I can upload it somewhere and give you a link if it comes to it, but I'd rather not. I'll also  try another project from scratch and see if the issue persists.

Nov 21, 2011 at 3:07 PM
Edited Nov 21, 2011 at 3:08 PM

Unloaded event is called when you close the form with control or change tab item

Nov 21, 2011 at 3:08 PM

Scrub that, I just looked at the changes list for the latest build, and this is exactly the code that changed. So something is calling Unloaded about 1 second after drawing the initial map. I'm happy to investigate further, although I don't really know at this point what I'm looking at...

Nov 21, 2011 at 3:13 PM

Cross-posted there. None of my unload or close functions are being called, although something is calling it. I commented out the event handler assignment in the GMapControl constructor, just to see what would happen, and there is no more error and the control works fine.

So it looks like I need to discover why Unload is being called...

Nov 21, 2011 at 3:22 PM

just put the breakpoint there and check the stacktrace

Nov 21, 2011 at 3:50 PM

Everything above is just [External code], so I can't tell what's calling it.

This is the debug output. I can't see anything that looks obviously like a smoking gun though... The call to Unloaded is highlighted in red.

 

15:20:14.5 Starting Plan-G, build 3.0.0.17
15:20:14.5 OS is Microsoft Windows NT 6.1.7601 Service Pack 1
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\Plan-G3\bin\Debug\GMap.NET.WindowsPresentation.dll', Symbols loaded.
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\Plan-G3\bin\Debug\GMap.NET.Core.dll', Symbols loaded.
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\Plan-G3\bin\Debug\System.Data.SqlServerCe.dll'
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
15:20:14.7 InitDataFolder
15:20:14.7 Data Source = C:\Users\skyhawk\Documents\Plan-G Files\Data\PlanG3_FSX.sdf
15:20:14.7 Data Source = C:\Users\skyhawk\Documents\Plan-G Files\Data\PlanG3_FS9.sdf
15:20:14.7 Data Source = C:\Users\skyhawk\Documents\Plan-G Files\Data\UserWaypoints.sdf
15:20:14.7 Data Source = C:\Users\skyhawk\Documents\Plan-G Files\Data\MEF.sdf
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationUI\v4.0_4.0.0.0__31bf3856ad364e35\PresentationUI.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsFormsIntegration\v4.0_4.0.0.0__31bf3856ad364e35\WindowsFormsIntegration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Zoom: 0 -> 2
OnMapSizeChanged, w: 996, h: 434, size: {Width=2, Height=1}
15:20:15.9 Program in: C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\Plan-G3\bin\Debug
OnMapSizeChanged, w: 1066, h: 434, size: {Width=3, Height=1}
MapType: None -> OpenStreetMap
Zoom: 2 -> 9
15:20:16.0 Data in: C:\Users\skyhawk\Documents\Plan-G Files
OnMapOpen: 1
add TileLoader: 0 to GThreadPool
add TileLoader: 1 to GThreadPool
add TileLoader: 2 to GThreadPool
add TileLoader: 3 to GThreadPool
add TileLoader: 4 to GThreadPool
OnTileLoadStart - at zoom 9, time: 15:20:16.6034986
Thread[14] - try load: 9 - {X=254,Y=169}
Thread[17] - try load: 9 - {X=250,Y=169}
OnMapSizeChanged, w: 1066, h: 510, size: {Width=3, Height=1}
Thread[15] - try load: 9 - {X=256,Y=169}
Thread[13] - try load: 9 - {X=251,Y=169}
Thread[16] - try load: 9 - {X=255,Y=168}
OnTileLoadStart - at zoom 9, time: 15:20:16.6565016
Assembly.LoadFile: C:\Users\skyhawk\AppData\Local\GMap.NET\DllCache\SQLite_v74_NET4_x86\System.Data.SQLite.DLL
OnTileLoadStart - at zoom 9, time: 15:20:16.6795030
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\skyhawk\AppData\Local\GMap.NET\DllCache\SQLite_v74_NET4_x86\System.Data.SQLite.DLL'
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data.OracleClient\v4.0_4.0.0.0__b77a5c561934e089\System.Data.OracleClient.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll'
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
FreePageSpace in cache: 79.0625MB | 2530 pages
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\Plan-G3\bin\Debug\System.Data.SqlServerCe.Entity.dll'
Thread[14] - tile loaded: 32KB, 9 - {X=254,Y=169}
Thread[16] - tile loaded: 25KB, 9 - {X=255,Y=168}
Thread[14] - try load: 9 - {X=250,Y=169}
'Plan-G3.vshost.exe' (Managed (v4.0.30319)): Loaded 'Anonymously Hosted DynamicMethods Assembly'
Invalidate delta: 1286ms
Thread[17] - tile loaded: 32KB, 9 - {X=250,Y=169}
Thread[16] - try load: 9 - {X=251,Y=169}
Thread[14] - tile loaded: 32KB, 9 - {X=250,Y=169}
Thread[16] - tile loaded: 23KB, 9 - {X=251,Y=169}
Thread[15] - tile loaded: 28KB, 9 - {X=256,Y=169}
Thread[14] - try load: 9 - {X=254,Y=170}
Thread[13] - tile loaded: 23KB, 9 - {X=251,Y=169}
Thread[17] - try load: 9 - {X=256,Y=169}
Thread[15] - try load: 9 - {X=251,Y=170}
Thread[16] - try load: 9 - {X=253,Y=169}
Thread[17] - tile loaded: 28KB, 9 - {X=256,Y=169}
Thread[15] - tile loaded: 32KB, 9 - {X=251,Y=170}
Invalidate delta: 139ms
Thread[16] - tile loaded: 32KB, 9 - {X=253,Y=169}
Thread[14] - tile loaded: 34KB, 9 - {X=254,Y=170}
Thread[16] - try load: 9 - {X=255,Y=169}
Thread[17] - try load: 9 - {X=250,Y=170}
Thread[15] - try load: 9 - {X=251,Y=168}
Thread[17] - tile loaded: 11KB, 9 - {X=250,Y=170}
Thread[15] - tile loaded: 17KB, 9 - {X=251,Y=168}
Thread[17] - try load: 9 - {X=252,Y=169}
Thread[16] - tile loaded: 64KB, 9 - {X=255,Y=169}
Thread[14] - try load: 9 - {X=250,Y=168}
Thread[17] - tile loaded: 32KB, 9 - {X=252,Y=169}
Thread[15] - try load: 9 - {X=253,Y=170}
Thread[17] - try load: 9 - {X=256,Y=170}
Thread[15] - tile loaded: 20KB, 9 - {X=253,Y=170}
Thread[17] - tile loaded: 37KB, 9 - {X=256,Y=170}
Invalidate delta: 131ms
Thread[15] - try load: 9 - {X=255,Y=170}
Thread[17] - try load: 9 - {X=252,Y=168}
Thread[15] - tile loaded: 64KB, 9 - {X=255,Y=170}
Thread[16] - try load: 9 - {X=252,Y=170}
Thread[17] - tile loaded: 32KB, 9 - {X=252,Y=168}
Thread[15] - try load: 9 - {X=256,Y=168}
Thread[17] - try load: 9 - {X=253,Y=168}
Thread[16] - tile loaded: 32KB, 9 - {X=252,Y=170}
Thread[15] - tile loaded: 32KB, 9 - {X=256,Y=168}
Thread[16] - Wait 0 - 15:20:17.6935610
Thread[17] - tile loaded: 30KB, 9 - {X=253,Y=168}
Invalidate delta: 117ms
Thread[14] - tile loaded: 32KB, 9 - {X=250,Y=168}
Thread[15] - Wait 1 - 15:20:17.7295630
Thread[13] - try load: 9 - {X=254,Y=168}
Thread[17] - Wait 2 - 15:20:17.7425638
Thread[13] - tile loaded: 32KB, 9 - {X=254,Y=168}
Thread[14] - Wait 3 - 15:20:17.7515643
Thread[13] - Wait 4 - 15:20:17.7565646
Thread[13] - OnTileLoadComplete: 1079ms, MemoryCacheSize: 0.663539886474609MB
Invalidate delta: 141ms
OnMapSizeChanged, w: 1082, h: 548, size: {Width=3, Height=2}
OnTileLoadStart - at zoom 9, time: 15:20:18.6766172
Invalidate delta: 811ms
Thread[14] - try load: 9 - {X=255,Y=167}
Thread[16] - try load: 9 - {X=253,Y=171}
OnTileLoadStart - at zoom 9, time: 15:20:18.6826175
Thread[17] - try load: 9 - {X=253,Y=167}
Thread[14] - tile loaded: 32KB, 9 - {X=255,Y=167}
Thread[16] - tile loaded: 32KB, 9 - {X=253,Y=171}
Thread[13] - try load: 9 - {X=252,Y=171}
GMapControl_Unloaded
Thread[14] - try load: 9 - {X=252,Y=171}
Thread[16] - try load: 9 - {X=254,Y=171}
Thread[17] - tile loaded: 32KB, 9 - {X=253,Y=167}
OnMapClose: 0
Thread[17] - try load: 9 - {X=250,Y=167}
Thread[14] - tile loaded: 28KB, 9 - {X=252,Y=171}
Thread[16] - tile loaded: 32KB, 9 - {X=254,Y=171}
Thread[15] - try load: 9 - {X=253,Y=167}
Thread[13] - tile loaded: 28KB, 9 - {X=252,Y=171}
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.Core.dll
CacheEngine: CancelTileCaching...
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.Core.dll
Thread[17] - tile loaded: 16KB, 9 - {X=250,Y=167}
OnMapOpen: 1
Thread[15] - tile loaded: 32KB, 9 - {X=253,Y=167}
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.Core.dll
Thread[16] - ProcessLoadTask: System.NullReferenceException: Object reference not set to an instance of an object.
   at GMap.NET.Internals.Core.ProcessLoadTask() in C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\GMap.NET.Core\GMap.NET.Internals\Core.cs:line 1061
Thread[14] - ProcessLoadTask: System.NullReferenceException: Object reference not set to an instance of an object.
   at GMap.NET.Internals.Core.ProcessLoadTask() in C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\GMap.NET.Core\GMap.NET.Internals\Core.cs:line 1061
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.Core.dll
Thread[16] - Wait 0 - 15:20:27.9361468
Thread[14] - Wait 1 - 15:20:27.9531478
Thread[17] - ProcessLoadTask: System.NullReferenceException: Object reference not set to an instance of an object.
   at GMap.NET.Internals.Core.ProcessLoadTask() in C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\GMap.NET.Core\GMap.NET.Internals\Core.cs:line 1061
Thread[15] - ProcessLoadTask: System.NullReferenceException: Object reference not set to an instance of an object.
   at GMap.NET.Internals.Core.ProcessLoadTask() in C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\GMap.NET.Core\GMap.NET.Internals\Core.cs:line 1061
Thread[13] - ProcessLoadTask: System.NullReferenceException: Object reference not set to an instance of an object.
   at GMap.NET.Internals.Core.ProcessLoadTask() in C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\GMap.NET.Core\GMap.NET.Internals\Core.cs:line 1061
Thread[17] - Wait 2 - 15:20:27.9711488
Thread[15] - Wait 3 - 15:20:28.0031506
Thread[13] - Wait 4 - 15:20:28.0061508
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.WindowsPresentation.dll
A first chance exception of type 'System.NullReferenceException' occurred in GMap.NET.Core.dll
System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionPlan-G3.vshost.exeSystem.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Object reference not set to an instance of an object.   at GMap.NET.Internals.Core.ProcessLoadTask() in C:\Users\skyhawk\Documents\Visual Studio 2010\Projects\Plan-G3\GMap.NET.Core\GMap.NET.Internals\Core.cs:line 939
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

Nov 21, 2011 at 3:57 PM

can you add the breakpoint?

Nov 21, 2011 at 4:00 PM

Yes I can add the breakpoint.