Tuesday, January 4, 2011

Tracking down a simple bug

 

What are the steps to tracking down a bug?

What is your system?

 

Well I like to first look at what I am trying to achieve:

Add/Delete data from the map and having the changes appear at another client automatically.

What is the current change?

Deleting data automatically affects other clients.

The bug:

When deleting Boo entities all other Boo entities on the screen get deleted.

Tracking down the code that is probably responsible:

        private void AreDeletedTask_ExecuteCompleted(object sender, QueryEventArgs e)

        {

            var toDelete = new List<Graphic>();

            foreach (var graphic in Graphics)

            {

                var id = GetObjectId(graphic);

                if ((e.FeatureSet.ObjectIDs == null || !e.FeatureSet.ObjectIDs.Contains(id)) &&

                    graphic.Geometry.Extent.Intersects(_map.Extent))

                    toDelete.Add(graphic);

            }

 

            foreach (var graphic in toDelete)

            {

                Graphics.Remove(graphic);

            }

        }

Just from looking at the code I can tell that the toDelete list must contain all the graphic elements in the extent.

So what do we have here? This is the result of a task that queries elements missing from an update to the current extent.

Let say I have a,b,c,d Boo elements.

a,b – were deleted

c – was unchanged

d – was updated

Only b,c,d are in the extent.

The query will be on the existence of a,b,c.

The result given to this method should contain only c element.

toDelete should contain b only.

But what about the case:

a – was deleted

b,c,d – were unchanged

The query will be on the existence of a, and will return null.

Now toDelete will contain a,b,c,d – Found The Bug!