ArgumentOutOfRangeException on GMapOverlay.DrawRoutes(...)

Topics: Bugs, Help
May 16, 2013 at 11:33 AM
Hey radioman. I am using the GMap.NET V1.6. I have gotten an ArgumentOutOfRangeException several times coming from the GMapOverlay.DrawRoutes(...) routine which is breaking my application. I'm curious if this is something you've ever seen. I've included the call stack. Maybe you can make out something I'm not seeing.

The trouble is that my application bangs out back to my Program.Main() where I'm launching my form, so I can't just catch the exception and proceed. So I'm not sure where that call to re-paint the map is even coming from.

Is it possible for you to catch that exception in the routine so that the application doesn't break?

Any suggestions?
System.ArgumentOutOfRangeException was unhandled
  Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       at System.Collections.Generic.List`1.get_Item(Int32 index)
       at GMap.NET.WindowsForms.GMapOverlay.DrawRoutes(Graphics g)
       at GMap.NET.WindowsForms.GMapOverlay.Render(Graphics g)
       at GMap.NET.WindowsForms.GMapControl.OnPaintOverlays(Graphics g)
       at GMap.NET.WindowsForms.GMapControl.OnPaint(PaintEventArgs e)
       at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
       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.UserControl.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at FAA.Spectrum.Foxhunt.Client.Program.Main(String[] args) in C:\Users\Michael\Documents\Visual Studio 2010\Projects\FAA.Spectrum\FAA.Spectrum.Foxhunt.Client\Program.cs:line 23
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
May 16, 2013 at 12:46 PM
Not sure what your thoughts are on this approach, radioman. But I'm thinking this is all I really need to do in order to catch the problem:
    internal partial class Map : GMapControl
        public Map()

        protected override void OnPaint(PaintEventArgs e)
            catch (ArgumentOutOfRangeException)
                // Discard - it's a bug in the original control
May 16, 2013 at 2:04 PM
i don't care for the old versions, and i've never had any issues with the latest, maybe you are doing some weird threading...
May 16, 2013 at 2:42 PM
I'm absolutely doing threading. And I'm quite sure that is where the issue is coming from.

I'm still using 1.6 since it's your latest "Stable" release. Do you have plans of creating a new "Stable" version? Or do you think there is significant value added in me switching over to the latest Hot Build right now?
May 16, 2013 at 2:45 PM
update GUI objects in GUI thread, and there will be no issues
May 16, 2013 at 3:23 PM
So I'd need to invoke the UI every time I update a routes points?
May 16, 2013 at 3:37 PM
backgroundworker work fine for that, all demos use that