ThinkGeo.com    |     Documentation    |     Premium Support

Proj4Projection - Attempted to read or write protected memory

Hi,


I've been working with the same three lines of code for about 6 hours now, and I'm at a loss.  I'm trying to take a shape delivered from SQL in WKT, reproject it as a VETile, and then get the bitmap and return it.  I can load the WKT fine.  However, if I try to reproject it.  I get an error.  The error occurs when calling getbitmap, but the stack trace shows that the violation actually occurs when accessing the projection.  The result is the same in the web edition as in the desktop edition.  Below is the error and some of the code.  ANY help would be appreciated. 


 


[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]    ThinkGeo.MapSuite.Core.Proj4Projection.pj_init(Int32 argc, String[] args) +0    ThinkGeo.MapSuite.Core.Proj4Projection.OpenCore() +185    ThinkGeo.MapSuite.Core.FeatureSource.Open() +84    ThinkGeo.MapSuite.Core.VectorLayer.OpenCore() +25    ThinkGeo.MapSuite.Core.Layer.Open() +12    ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas, Object nativeImage, RectangleShape canvasExtent, GeographyUnit mapUnit) +217    ThinkGeo.MapSuite.DesktopEdition.x65fdca92d79c01f5.x2d1a07f71f20336d(Int32 xa209325f5c895f7e, Int32 x7454a0d1965919b1, Boolean xcdc4574d58d5c2d6) +1331    ThinkGeo.MapSuite.DesktopEdition.WinformsMap.GetBitmap(Int32 width, Int32 height) +19    ThinkGeoImage.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Grant Hamm\My Documents\Visual Studio 2008\Projects\ThinkGeoImage\ThinkGeoImage\WebForm1.aspx.vb:95    System.Web.UI.Control.OnLoad(EventArgs e) +99    System.Web.UI.Control.LoadRecursive() +50    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


 


Dim mapShapeLayer As InMemoryFeatureLayer = New InMemoryFeatureLayer()

                        mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(255, Item.FillColor.R, Item.FillColor.G, Item.FillColor.B)

                        mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.FromArgb(255, Item.LineColor.R, Item.LineColor.G, Item.LineColor.B)

                        mapShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

                        mapShapeLayer.InternalFeatures.Add(AWhereReader("UniqueFeatureValue") & count, x)

                        Dim proj4 As New Proj4Projection



                        proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326)

                        proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString

                        mapShapeLayer.FeatureSource.Projection = proj4

                        Map1.StaticOverlay.Layers.Add(AWhereReader("UniqueFeatureValue") & count, mapShapeLayer)

                        


That's the code to load a WKT shape.


 


Then the bitmap call is just:


Map1.CurrentExtent = New RectangleShape(-105.5, 39.9, -105.45, 39.4)


Map1.MapUnit = GeographyUnit.Meter

        img = Map1.GetBitmap(256, 256)

        img.Save("C:\test123.png")


 


Thanks in advance!


 


 


 


 


 


 



This is something else I tried.  It fails on proj4.open() giving the same accessviolation.  This is almost verbatim what was reccomended to another user in another post, yet it’s failing on the open call.  Is this a bug? 
  
 Dim proj4 As Proj4Projection = New Proj4Projection 
                 proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326) 
                 proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString 
                 Dim y As BaseShape = BaseShape.CreateShapeFromWellKnownData(WKTString) 
                 proj4.Open() 
                 Dim x As New Feature(proj4.ConvertToExternalProjection(y)) 
                 proj4.Close()

 


Tom,
 
About the 1st post, you need to Open the projection before GetBitmap, you can add one line during the initialization
proj4.Open();
or you can add it just before GetBitmap, code should be something like
((FeatureLayer)Map1.StaticOverlay.Layers["Key"]).FeatureSource.Projection.Open();
 
The method projection.Open() does initialization work for the projection which is a bit expensive. That's why we didn't call it automatically inside GetBitmap and expose it to users so you can get more controls with performance benefits. For example, if you want to call GetBitMap 10 times (let’s say it’s in a loop), you can open the projection at the very beginning and close the projection at the very end. Then they only need to be initialized once instead of 10 times.
 
Also we will change the Exception Message to make users easier find what’s going on.
 
About the 2nd post, I copied your code and it works fine without any exception. (Of course I set a WKT myself) Can you make sure you are now using the latest version (3.0.115) and if still have problem, can you make a simple demo and send to me? I think there are some other things going wrong.
 
Ben.

Ben,


Thanks for the late night reply, you've definitely helped us out quite a bit.


 


So the problem is now fixed.  All I ended up doing was creating a new project.  I'm not entirely sure what happened, but while developing in this project, i upgraded versions, and all I can figure is that it left fingerprints somewhere that caused the problem.  Now it works fantastic!  Thanks again for the support.


 



You are welcome:) I am happy it helps.