Unhandled exceptions: System.ArgumentException and System.OutOfMemoryException

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Dec 20, 2012 at 2:01 PM

Hello,

What to do with this errors, a co-worker got on his PC, but not on my PC with VS 2010, even in Debug mode?

Application: SharpRoutes.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException
Stack:
   at System.Drawing.Bitmap..ctor(Int32, Int32, System.Drawing.Imaging.PixelFormat)
   at System.Drawing.Bitmap.MakeTransparent(System.Drawing.Color)
   at SharpMap.Forms.MapBox.GetMap(SharpMap.Map, SharpMap.Layers.LayerCollection, SharpMap.Layers.LayerCollectionType, SharpMap.Geometries.BoundingBox)
   at SharpMap.Forms.MapBox.GetImagesAsync(SharpMap.Geometries.BoundingBox, Int32)
   at SharpMap.Forms.MapBox+<>c__DisplayClass13.<UpdateImage>b__10(System.Object)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
   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()

and

Application: SharpRoutes.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.OutOfMemoryException
Stack:
   at SharpRoutes.mapForm.RoadSegmentStyle(SharpMap.Data.FeatureDataRow)
   at SharpMap.Rendering.Thematics.CustomTheme.GetStyle(SharpMap.Data.FeatureDataRow)
   at SharpMap.Layers.VectorLayer.RenderInternal(System.Drawing.Graphics, SharpMap.Map, SharpMap.Geometries.BoundingBox, SharpMap.Rendering.Thematics.ITheme)
   at SharpMap.Layers.VectorLayer.Render(System.Drawing.Graphics, SharpMap.Map)
   at SharpMap.Map.RenderMap(System.Drawing.Graphics, SharpMap.Layers.LayerCollectionType, Boolean)
   at SharpMap.Forms.MapBox.GetMap(SharpMap.Map, SharpMap.Layers.LayerCollection, SharpMap.Layers.LayerCollectionType, SharpMap.Geometries.BoundingBox)
   at SharpMap.Forms.MapBox.GetImagesAsync(SharpMap.Geometries.BoundingBox, Int32)
   at SharpMap.Forms.MapBox+<>c__DisplayClass13.<UpdateImage>b__10(System.Object)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
   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 use SharpMap 0.9.4507.23600.

It happens when the map gets refreshed. The map contains a VectorLayer ([big] shapefile), with a custom Theme:

        private VectorStyle RoadSegmentStyle(FeatureDataRow row)
        {
            VectorStyle segmentStyle = new VectorStyle();
            string finalName = row["NAME"].ToString().ToUpper();
            bool hasName = (finalName != string.Empty);
            bool hasSpecialName = finalName.StartsWith("["|| _specialNames.Contains(finalName);
            Color lineColor = (hasName ? (hasSpecialName ? Color.MediumBlue : Color.Black) : Color.Red);
            float lineWidth = (hasName && !hasSpecialName ? 2 : 1);
 
            segmentStyle.Enabled = true;
 
            segmentStyle.Line = new Pen(lineColor, lineWidth);
            segmentStyle.Line.StartCap = System.Drawing.Drawing2D.LineCap.Round;
            segmentStyle.Line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            segmentStyle.Line.CustomEndCap = new System.Drawing.Drawing2D.AdjustableArrowCap(33true);
 
            return segmentStyle;
        }

and a LabelLayer based on the VectorLayer.

Do I have to change the source (SpatiaLite, ...) ?

Greetings,

Pieter

Coordinator
Dec 20, 2012 at 2:18 PM

It seems that you run out of memory when trying to create the bitmap to draw on..
I've seen that error when the size of the Map is 0x0pixels or similar.
This is fixed in sourcecode-trunk but remains in the last version available from downloads.

Could it be that map is drawn before the mapbox gets its size set?

 

 

 

Jan 14, 2013 at 1:32 PM

Because of end-of-year holidays I couldn't answer earlier.

What do you mean with "map is drawn before the mapbox gets its size set" ? The mapbox is on a form, and has a certain size. I add several layers and as OSM background.

Have a nice day,

Pieter