Exception during GMapOverlay.Render()

Topics: Windows Forms
Nov 4, 2010 at 3:22 PM

Hi radioman,

I am running into some trouble during GMapOverlay.Render()

Recent progress in our application has us placing, at times, hundreds or thousands of markers on the map.  While iterating in these two blocks, it is possible for implementation to add/remove/move marker from the list.  The collection iterator becomes invalid and an exception is raised.  But the implementing application does not have the opportunity to catch this exception and handle it elegantly (because it occurs in the UI thread).

              // markers
               foreach(GMapMarker m in Markers)
               {
                  if(m.IsVisible && (m.DisableRegionCheck || Control.Core.currentRegion.Contains(m.LocalPosition.X, m.LocalPosition.Y)))
                  {
                     m.OnRender(g);
                  }
               }

               // tooltips above
               foreach(GMapMarker m in Markers)
               {
                  if(m.ToolTip != null && m.IsVisible && Control.Core.currentRegion.Contains(m.LocalPosition.X, m.LocalPosition.Y))
                  {
                     if(!string.IsNullOrEmpty(m.ToolTipText) && (m.ToolTipMode == MarkerTooltipMode.Always || (m.ToolTipMode == MarkerTooltipMode.OnMouseOver && m.IsMouseOver)))
                     {
                        m.ToolTip.Draw(g);
                     }
                  }
               }

Perhaps in GMap.NET.ObjectModel.ObservableCollection, add/remove/insert methods could be wrapped with a lock on a SyncRoot object, then during the render, the above blocks could lock on the same syncroot.  This would at least prevent exceptions from orginating in the GMap.NET library.  If the SyncRoot object were public, the implementing application might be able to utilize it as well.

Does this seem like a reasonable solution, or do you know of a better way?  Or am I just doing something wrong?  Thanks for your help, and keep up the good work!

Coordinator
Nov 4, 2010 at 4:10 PM

i guess so, i'll check this

Jan 20, 2011 at 4:07 PM

I wanted to mark this as a non-bug.  This exception was occurring because of a missing Invoke() on my behalf.

Coordinator
Jan 20, 2011 at 4:24 PM

i see