ThinkGeo.com    |     Documentation    |     Premium Support

A random SkiaSharp related unhandled exception

Hi all,

We’ve been encountering an unhandled AccessViolationException in our automated test environment every now and then. The rate of occurrence is very low though, less than 1%. It is happening across different test machines so failing memory hardware is probably ruled out.

Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
   at SkiaSharp.SKPath.GetBounds(SkiaSharp.SKRect ByRef)
   at 7BQ=.MxU=.SxU=(System.String, ThinkGeo.Core.GeoFont)
   at ThinkGeo.Core.ScaleLineAdornmentLayer.HiA=(System.String, ThinkGeo.Core.GeoFont, Int32, ThinkGeo.Core.GeoCanvas)
   at ThinkGeo.Core.ScaleLineAdornmentLayer.HSA=(ThinkGeo.Core.GeoCanvas)
   at ThinkGeo.Core.ScaleLineAdornmentLayer.DrawCore(ThinkGeo.Core.GeoCanvas, System.Collections.ObjectModel.Collection`1<ThinkGeo.Core.SimpleCandidate>)
   at ThinkGeo.Core.Layer.Rh8=(ThinkGeo.Core.GeoCanvas, System.Collections.ObjectModel.Collection`1<ThinkGeo.Core.SimpleCandidate>)
   at ThinkGeo.Core.Layer.Draw(ThinkGeo.Core.GeoCanvas, System.Collections.ObjectModel.Collection`1<ThinkGeo.Core.SimpleCandidate>)
   at System.Threading.Tasks.Task.Execute()
   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.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

The problem comes from the start of the application when user first navigates to the map. I think we have narrowed down where the problem probably originates from. Here’s a simplified code snippet of how the ScaleLineAdornmentLayer is added.

MapView.AdornmentOverlay.Layers.Clear();

var scale = new ScaleLineAdornmentLayer
{
	Name = ScaleName,
	UnitSystem = ScaleUnitSystem,
	Location = ScaleLocation,
	XOffsetInPixel = scaleXOffset,
	YOffsetInPixel = scaleYOffset
};
scale.TextStyle.Font.Size = ScaleFontSize;
scale.Projection = ProjectionService.CurrentProjectionConverter.ExternalProjection;
   
MapView.AdornmentOverlay.Layers.Add(adornmentOverlay);

MapView.Overlays.Clear();
await MapView.RefreshAsync();

We are still using ThinkGeo 13.2 and for now cannot yet upgrade to 14.0 to try whether it still happens, for reasons we might be covering in another post. But does anyone have any ideas why this might be happening? Something in the way ScaleLineAdornmentLayer uses the fonts maybe?

Best Regards,
Jarno

Hi Jarno,

I found the exception is thrown when executing textPath.GetBounds(out bounds) The code is like following:

SKPaint paint = GetSKPaintFromGeoFont(font);
SKPath textPath = paint.GetTextPath(textLine, 0, 0);
textPath.GetBounds(out bounds);

That textLine is always valid, so it means in your test case, 1 out of 100 the SKPaint is somehow not valid. I have no clue after reviewing the code, I’m thinking:

  1. The exception is thrown from Skia and it could be a bug in SkiaSharp. Can you update it to the latest SkiaSharp see if things gets better? ThinkGeo v14 is referencing the latest SkiaSharp 2.88.8, but you can also do the update while keep using your current version.
  2. Any chance you can create a demo, by putting the test code in a loop or something to recreate this issue? After that we will know for sure if it only happens on your test server or on all the machines.

Thanks,
Ben