Select to view content in your preferred language

NullReferenceException when using EditGeometry

2975
14
12-28-2011 05:23 PM
Labels (1)
Hwee_KiangSim
Emerging Contributor
Hi,

i using esri for WPF v2.3. When I use the EditGeometry, sometimes I experience a NullReferenceException and my app will crash. I cant seem to catch the exception to let my app exit gracefully and I cant seem to debug it because it has something to do with the esri dll. The most I can see in the call stack is it crashes at the point of EditGeometry.UpdateVertexPosition (i think it's a private function in the dll?) and normally occur after EditGeometry.Action == EditCanceled (but I did not explicitly call EditCancel())

The exception is random and occurs on and off which is a headache. Please help. Thanks

shweekia
0 Kudos
14 Replies
Hwee_KiangSim
Emerging Contributor
Hi Jennifer,

I tried using the sample codes you provided but I realised that the update event does not fire when I perform a geometry move (move entire graphic). Similarly when I move the geometry, the editgeometry event is triggered but it does not tell me the delta moved(olditems and newitems are null).

Is there any way I can get this delta or at the very least get an update event when I move the geometry or am I back to square one again?

Thanks so much again.
0 Kudos
JenniferNery
Esri Regular Contributor
What type of Geometry are you moving? EditGeometry only supports Polyline/Polygon. MapPoints are handled differently as in this example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsGeometry.
0 Kudos
Hwee_KiangSim
Emerging Contributor
I am using polygons. I just realised that propertychanged will only be triggered AFTER I end the edit. I want it to be triggered during edits. So looks like I cant use propertychanged event afterall.


And although an event has been triggered at EditGeometry.Action.GeometryMoved, it does not tells me the delta moved.

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
Yes, that's right. But you know the original Geometry (before StartEdit()) and resulting Geometry after GeometryMoved (after StopEdit()), you can then compare the distance between the two geometries. In future versions, you would not need to call StopEdit() to get the current state of geometry.
0 Kudos
JoshuaLeask
New Contributor
I've got this issue and it's causing me some grief. So I've reproduced it using the supplied examples.

In EditToolsGeometry.xaml add the MouseRightButtonDown event to the map.
<esri:Map x:Name="MyMap" Extent="-16574645.619,-5541958.774,13341035.686,10559275.713" Loaded="MyMap_Loaded"
                  esri:Editor.SnapDistance="30"
                  MouseClick="MyMap_MouseClick" 
                  MouseMove="MyMap_MouseMove"
                  MouseLeftButtonUp="MyMap_MouseLeftButtonUp"
                  MouseRightButtonDown="MyMap_OnMouseRightButtonDown">


Then in the event handler add a Polyline per click. This bug only occurs when they're added in code behind.
private void MyMap_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            PointCollection pointCollection = new PointCollection { new MapPoint(0, 0), MyMap.ScreenToMap(e.GetPosition(MyMap)) };
            Polyline polyline = new Polyline();
            polyline.Paths.Add(pointCollection);
            Graphic graphic = new Graphic
            {
                Symbol = LayoutRoot.Resources["MyScaleBox"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                Geometry = polyline
            };

            ((GraphicsLayer)MyMap.Layers["MyGraphicsLayer"]).Graphics.Add(graphic);
            ((GraphicsLayer)MyMap.Layers["MyGraphicsLayer"]).Refresh();

        }


Then move the a vertex around until you get the exception. This appears to be a race condition as the UpdateVertexPosition(MapPoint pnt, bool isTransformPoint) method checks DraggingVertex isn't null but by the time it gets to near the end of the method it is null.



0 Kudos