This project has moved and is read-only. For the latest updates, please go here.
1
Vote

GetMap System.AccessViolationException

description

I have created a windows desktop mapping application, using SharpMap 1.1, together with VB.NET (framework 4.0), and PostgreSQL as the spatial database.

My users (a State Bushfire Authority) have been using this application for over a year now with a large degree of success and enjoyment (well done and thank you to the developers of SharpMap).

However every now and then, most users experience a crash when using the application (message pops up saying something like: 'BRIMap.exe has stoped working and needs to close'. When looking in the Windows Application Logs, there is always a .NET Runtime error recorded which says:

Application: BRIMap.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Drawing.SafeNativeMethods+Gdip.GdipPathIterNextSubpathPath(System.Runtime.InteropServices.HandleRef, Int32 ByRef, System.Runtime.InteropServices.HandleRef, Boolean ByRef)
at System.Drawing.Drawing2D.GraphicsPathIterator.NextSubpath(System.Drawing.Drawing2D.GraphicsPath, Boolean ByRef)
at SharpMap.Rendering.Symbolizer.WarpPathToPath.Warp(System.Drawing.Drawing2D.GraphicsPath, System.Drawing.Drawing2D.GraphicsPath, Boolean, Single)
at SharpMap.Rendering.Symbolizer.WarpPathToPath.DrawString(System.Drawing.Graphics, System.Drawing.Pen, System.Drawing.Brush, System.String, System.Drawing.FontFamily, Int32, Single, System.Drawing.StringFormat, Boolean, System.Drawing.Drawing2D.GraphicsPath)
at SharpMap.Layers.LabelLayer.Render(System.Drawing.Graphics, SharpMap.Map)
at SharpMap.Map.RenderMap(System.Drawing.Graphics, SharpMap.Layers.LayerCollectionType, Boolean, Boolean)
at SharpMap.Forms.MapBox.GetMap(SharpMap.Map, SharpMap.Layers.LayerCollection, SharpMap.Layers.LayerCollectionType, GeoAPI.Geometries.Envelope)
at SharpMap.Forms.MapBox.GetImagesAsync(GeoAPI.Geometries.Envelope, Int32)
at SharpMap.Forms.MapBox+<>c__DisplayClass15.<UpdateImage>b__11(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

I am using the SharpMap.Forms.MapBox control and the SharpMap.Forms.ToolBar.MapZoomToolStrip for panning and zooming operations and SharpMap.Forms.ToolBar.MapDigitizeGeometriesToolStrip for capturing new geometries.

It appears to be some form of memory issue because it occurs randomly, often when users are panning or zooming, or creating geometries, but can occur at other times when the map does not appear to be in use. The error above suggests it occurs when labels are being rendered to the map, however I don't think it is data related, because most of the time all labels display fine, for all areas of the map (the error is not triggered by zooming to any particular map extent).

The error tends to occur more frequently on lower spec PCs (with less memory). Users PCs are a combination of windows 7 and windows 8.

I am developing in VS Express 2012 for desktop.

Does anyone have any suggestions as to how I might deal with this issue. Is it worth trying a newer (non-stable) version of the SharpMap dlls?

comments

FObermaier wrote Jan 1, 2016 at 2:43 PM

It seems to be a threading issue.
I'll have a look at it.

WildHeart wrote Feb 27, 2016 at 9:44 PM

Hi FObermaier,

Just wondering if you had any luck with this issue?

FObermaier wrote Mar 14, 2016 at 11:50 PM

Are you using SharpMap from a released nuget package or did you compile it yourself?
If you are compiling yourself, could you try attributing the Warp function like this:
[MethodImpl(MethodImplOptions.Synchronized)]
public static GraphicsPath Warp(GraphicsPath pathToWarpTo, GraphicsPath pathToWarp, bool isPattern, float interval)
{
    // ...
}

WildHeart wrote Mar 15, 2016 at 10:05 PM

I am using the compiled SharpMap libraries from a nuget package, so am not compiling. What effect will the suggested Warp changes have on the this issue?

If necessary, I can make the changes and compile.

WildHeart wrote Mar 15, 2016 at 10:12 PM

After a bit of reading, I have more of an idea of why you suggested making the change:

definition of MethodImplOptions.Synchronized from msdn:

'The method can be executed by only one thread at a time. Static methods lock on the type, whereas instance methods lock on the instance. Only one thread can execute in any of the instance functions, and only one thread can execute in any of a class's static functions.'

I will make the change and see how I go.
Thanks

FObermaier wrote Mar 17, 2016 at 11:20 AM

Please report back how it works

WildHeart wrote Mar 18, 2016 at 1:42 AM

OK, I have made the change as suggested, recompiled, and placed the new sharmap.dll in my deployment. I will get a user to test and will let you know the results.

WildHeart wrote May 4, 2016 at 3:54 AM

Happy to report that its been over a month now and users have not experienced the System.AccessViolationException error (the application has been used fairly heavily in this period of time).

It looks like your suggestion of using MethodImplOptions.Synchronized solved the problem.

Thanks for your help on this. We really appreciate it.