zeta243 / osmdroid

Automatically exported from code.google.com/p/osmdroid
1 stars 0 forks source link

Intermitent ANR on calling zoomToSpan #313

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
There are already issues for this but they are old and marked as want fix hence 
a new issue.

What steps will reproduce the problem?
1. I have a activity with a MapView that loads a PathOverlay in an AsyncTask.
2. I call zoomToSpan in postExecute
3. intermitently when the loading is quick I get an ANR error

What is the expected output? What do you see instead?
The map to zoom to show the path I have loaded.
The screen is still black my activity has never drawn fully when the system 
hangs and I get an ANR

What version of the product are you using? On what operating system?
3.0.7 and code as of revision 1080

Please provide any additional information below.

The thread is stuck in getNextSquareNumberAbove(float factor) in MyMaths.java

factor is comming in as Infinity and the while loop never exits.  I have not 
traced back the calling into this to work out the route cause but somthing is 
clearly not initalised and I have a race condition of some form.

The attached version of MyMath.java tests for this condition and thus will 
avoid the ANR although the zoomToSpan will not zoom correctly.  It writes to 
the log on detecting the problem.

Original issue reported on code.google.com by iforpow...@gmail.com on 22 Feb 2012 at 6:18

Attachments:

GoogleCodeExporter commented 8 years ago
I had this problem every time I tried to use zoomToSpan.
This was always in Activity onCreate().

Then i noticed that the MapView has a similar method:

zoomToBoundingBox(BoundingBoxE6 boundingBox)

The documentation for zoomToBoundingBox states:

"Zoom the map to enclose the specified bounding box, as closely as possible. 
Must be called after display layout is complete, or screen dimensions are not 
known, and will always zoom to center of zoom level 0."

My MapView always has dimensions of zero pixels square in onCreate, so using 
some code i found on StackOverflow i came up with this solution:

public void fitMapToMarkers() {
    Log.d("B4A", "MapView has height of " + mMapView.getHeight());
    if (mMapView.getHeight() > 0) {
        Log.d("B4A", "Debug #1a");
        //  mMapView.getController().zoomToSpan(mOverlayItemsBounds);   //  does not work but no ANR
        mMapView.zoomToBoundingBox(mOverlayItemsBounds);    //  works
    } else {
        //  wait for layout
        ViewTreeObserver vto1 = mMapView.getViewTreeObserver();
        vto1.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Log.d("B4A", "Debug #2a");
                //  mMapView.getController().zoomToSpan(mOverlayItemsBounds);   //  does not work but no ANR
                mMapView.zoomToBoundingBox(mOverlayItemsBounds);    //  works
                ViewTreeObserver vto2 = mMapView.getViewTreeObserver();
                vto2.removeGlobalOnLayoutListener(this);
            }
        });
    }
}

mOverlayItemsBounds is an ArrayList of GeoPoints.

Original comment by warwo...@gmail.com on 18 Mar 2012 at 12:38

GoogleCodeExporter commented 8 years ago
I tested MyMath.getNextSquareNumberAbove(float factor) by throwing in values of 
1,10,100,1000 and so on and noticed that it would work perfectly fine with 1E9 
and freeze (loop forever) with 1E10.

Original comment by bastis...@googlemail.com on 5 Jun 2012 at 1:36