ThinkGeo.com    |     Documentation    |     Premium Support

V12.1 - AccessViolation Clearing MrSid Layer

ThinkGeo Team,

Intermittently I’m seeing System.AccessViolationException from ThinkGeo.Dependency.Gdal.dll.

This is occurring somewhere during the following code:

if (TheFeatureLayer.IsOpen == true)
{
    TheFeatureLayer.Close();
}

TheLayerOverlay.Layers.Clear();

TheMapView.Refresh();

Here’s errors while in Debug Mode:

System.AccessViolationException HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=
StackTrace:

An unhandled exception of type ‘System.AccessViolationException’ occurred in ThinkGeo.Dependency.Gdal.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The program ‘[7216] OriStarRaster.exe’ has exited with code -1073741819 (0xc0000005) ‘Access violation’.

My code has try/catch logic as well as both the LayerOverlay and RasterLayer Drawing/Drawn Exceptions implemented and still not able to catch this exception…

Looks to me like it is a timing issue.

This occurs more often when the application is started directly as opposed to running in Debug Mode.

I should add too that the application has a push button to invoke the above code leaving the application running. I’ve never seen this if I just shut down the application.

This issue might be related to, or aggravated by, LayerOverlay.TileBuffer. It set to 0 the access violation does not occur, but when set to 2 it does occur.

Regards,
Dennis

Thanks Dennis,
Yes. I can reproduce this one. I think this because the MrSidLayer object not full release. You can use MrSidLayer = null; to release the object.

Here is the full code.

 private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (MrSidLayer.IsOpen == true)
            {
                MrSidLayer.Close();
            }
            MrSidLayer = null;
            overLay.Layers.Clear();
            map.Refresh();
        }

Thanks

Frank

hi Frank,

I’m afraid setting the layer to null does not change the situation.

I feel pretty confident this is a timing issue between the UI thread and ThinkGeo drawing threads.

What I think is occurring is that the Close() and Layers.Clear() are invoked while the drawing thread is still active and attempting to access memory that is no longer available.

Dennis

Thanks Dennis,
The MrsidLayer will Gdal which will use unmanaged libary. I did more test. It mostly likely happen when the map still drawing. So I added a check. Make sure the map has done drawing. I attached you the project.
Demo.zip (1.2 MB)

Thanks

Frank