KelvinAng95 / osmbonuspack

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

osmbonuspack throws out of bounds exception #15

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

I'm using the osmbonuspack for map routing and I'm having an issue of an out of 
bounds index. What is odd is that the same call is made over and over 
successfully with the same parameters then all of the sudden it breaks. Can you 
provide any clues to what is going on?

Thank you

12-05 16:20:34.070: E/AndroidRuntime(14825): FATAL EXCEPTION: main
12-05 16:20:34.070: E/AndroidRuntime(14825): 
java.lang.IndexOutOfBoundsException: Invalid index 17, size is 16
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
java.util.ArrayList.get(ArrayList.java:311)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
org.osmdroid.views.overlay.ItemizedOverlay.getItem(ItemizedOverlay.java:149)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
org.osmdroid.bonuspack.overlays.ItemizedOverlayWithBubble.draw(ItemizedOverlayWi
thBubble.java:137)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:119)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
org.osmdroid.views.MapView.dispatchDraw(MapView.java:869)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.View.draw(View.java:7022)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.widget.FrameLayout.draw(FrameLayout.java:357)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.View.draw(View.java:7022)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.widget.FrameLayout.draw(FrameLayout.java:357)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:191
7)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewRoot.draw(ViewRoot.java:1562)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewRoot.performTraversals(ViewRoot.java:1298)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.view.ViewRoot.handleMessage(ViewRoot.java:1900)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.os.Handler.dispatchMessage(Handler.java:99)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.os.Looper.loop(Looper.java:130)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
android.app.ActivityThread.main(ActivityThread.java:3691)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
java.lang.reflect.Method.invokeNative(Native Method)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
java.lang.reflect.Method.invoke(Method.java:507)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
12-05 16:20:34.070: E/AndroidRuntime(14825):    at 
dalvik.system.NativeStart.main(Native Method)

Original issue reported on code.google.com by shameus....@gmail.com on 10 Dec 2012 at 2:31

GoogleCodeExporter commented 8 years ago
The exception is raised in ItemizedOverlayWithBubble.draw method, in a section 
identical to osmdroid ItemizedOverlay.draw method. 

Look at this osmdroid issue: 
http://code.google.com/p/osmdroid/issues/detail?id=365

Does it seems similar to your issue?

Original comment by mathieu....@gmail.com on 10 Dec 2012 at 9:31

GoogleCodeExporter commented 8 years ago
Yes, this seems like the same issue. So a fix is still ongoing?

Original comment by shameus....@gmail.com on 11 Dec 2012 at 1:44

GoogleCodeExporter commented 8 years ago
No update since August... 
I just commited a new version of ItemizedOverlayWithBubble, introducing 
synchronize blocks to avoid this race condition (osmbonuspack_v3.1.jar in the 
Downloads). 
It still works on my tests, but I never encountered your issue. 
Can you test it?

Original comment by mathieu....@gmail.com on 12 Dec 2012 at 9:39

GoogleCodeExporter commented 8 years ago
12-12 17:01:32.215: E/AndroidRuntime(7575): FATAL EXCEPTION: main
12-12 17:01:32.215: E/AndroidRuntime(7575): 
java.lang.IndexOutOfBoundsException: Invalid index 18, size is 16
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
java.util.ArrayList.get(ArrayList.java:311)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
org.osmdroid.views.overlay.ItemizedOverlay.getItem(ItemizedOverlay.java:149)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
org.osmdroid.bonuspack.overlays.ItemizedOverlayWithBubble.draw(ItemizedOverlayWi
thBubble.java:141)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:119)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
org.osmdroid.views.MapView.dispatchDraw(MapView.java:872)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.View.draw(View.java:7022)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.widget.FrameLayout.draw(FrameLayout.java:357)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.View.draw(View.java:7022)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.widget.FrameLayout.draw(FrameLayout.java:357)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:191
7)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewRoot.draw(ViewRoot.java:1562)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewRoot.performTraversals(ViewRoot.java:1298)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.view.ViewRoot.handleMessage(ViewRoot.java:1900)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.os.Looper.loop(Looper.java:130)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
android.app.ActivityThread.main(ActivityThread.java:3691)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
java.lang.reflect.Method.invokeNative(Native Method)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
java.lang.reflect.Method.invoke(Method.java:507)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
12-12 17:01:32.215: E/AndroidRuntime(7575):     at 
dalvik.system.NativeStart.main(Native Method)

It lasted longer but still failed after the update.

Original comment by shameus....@gmail.com on 12 Dec 2012 at 10:02

GoogleCodeExporter commented 8 years ago
Hummmm... 
To be sure: I imagine you have threads. In your test, what are you doing in 
these threads, while drawing? 

Original comment by mathieu....@gmail.com on 13 Dec 2012 at 11:17

GoogleCodeExporter commented 8 years ago
I do have threads but I'm synchronizing access to the object that uses 
ItemizedOverlayWithBubble. I've doubled checked it.

Original comment by shameus....@gmail.com on 13 Dec 2012 at 5:14

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
At bottom level, the race condition occurs inside ItemizedOverlay.getItem(), at 
this line: mInternalItemList.get(position);

At top level, this is called by ItemizedOverlayWithBubble.draw()

I don't think you can synchronize between your threads and the draw, because 
you don't call the draw yourself (this is done by Android framework). 

What I don't understand is why my fix doesn't work. 
Could you provide a sample of your code? 

Original comment by mathieu....@gmail.com on 14 Dec 2012 at 2:41

GoogleCodeExporter commented 8 years ago
Sorry for the delay.

My Eclipse environment got completely corrupted. I'm still trying to get back 
up and running. Once that is done I'll verify that I'm using the correct lib 
with the new changes.

Original comment by shameus....@gmail.com on 14 Dec 2012 at 6:37

GoogleCodeExporter commented 8 years ago
I'm still getting the exception.

I've verified I've built the rev 119 of the bonuspack.

12-16 10:44:19.190: E/AndroidRuntime(10290): FATAL EXCEPTION: main
12-16 10:44:19.190: E/AndroidRuntime(10290): 
java.lang.IndexOutOfBoundsException: Invalid index 15, size is 13
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
java.util.ArrayList.get(ArrayList.java:311)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
org.osmdroid.views.overlay.ItemizedOverlay.getItem(ItemizedOverlay.java:149)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
org.osmdroid.bonuspack.overlays.ItemizedOverlayWithBubble.draw(ItemizedOverlayWi
thBubble.java:153)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:119)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
org.osmdroid.views.MapView.dispatchDraw(MapView.java:872)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.View.draw(View.java:7022)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.widget.FrameLayout.draw(FrameLayout.java:357)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.View.draw(View.java:7022)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.widget.FrameLayout.draw(FrameLayout.java:357)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:191
7)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewRoot.draw(ViewRoot.java:1562)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewRoot.performTraversals(ViewRoot.java:1298)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.view.ViewRoot.handleMessage(ViewRoot.java:1900)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.os.Handler.dispatchMessage(Handler.java:99)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.os.Looper.loop(Looper.java:130)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
android.app.ActivityThread.main(ActivityThread.java:3691)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
java.lang.reflect.Method.invokeNative(Native Method)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
java.lang.reflect.Method.invoke(Method.java:507)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
12-16 10:44:19.190: E/AndroidRuntime(10290):    at 
dalvik.system.NativeStart.main(Native Method)

Original comment by shameus....@gmail.com on 16 Dec 2012 at 3:50

GoogleCodeExporter commented 8 years ago
I think I might have found the problem with Index out of bounds exception. I 
was creating a new ItemizedOverlayWithBubble object with every iteration of the 
thread. I moved the creation into onCreate thus only being created once. I'll 
do more testing.

During testing the below exception crept up when calling this, 
RoadManager.buildRoadOverlay

12-16 14:06:55.050: E/AndroidRuntime(19734): FATAL EXCEPTION: main
12-16 14:06:55.050: E/AndroidRuntime(19734): java.lang.NullPointerException
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.DefaultResourceProxyImpl.getDisplayMetricsDensity(DefaultResourcePr
oxyImpl.java:133)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.views.overlay.Overlay.<init>(Overlay.java:64)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.views.overlay.PathOverlay.<init>(PathOverlay.java:66)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.views.overlay.PathOverlay.<init>(PathOverlay.java:62)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.bonuspack.routing.RoadManager.buildRoadOverlay(RoadManager.java:59)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.bonuspack.routing.RoadManager.buildRoadOverlay(RoadManager.java:79)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.Route.updateRoad(Route.java:110)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.Route$UpdateRoadTask.onPostExecute(Route.java:187)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
org.osmdroid.Route$UpdateRoadTask.onPostExecute(Route.java:1)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
android.os.AsyncTask.finish(AsyncTask.java:417)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
android.os.AsyncTask.access$300(AsyncTask.java:127)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
android.os.Handler.dispatchMessage(Handler.java:99)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
android.os.Looper.loop(Looper.java:130)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
android.app.ActivityThread.main(ActivityThread.java:3691)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
java.lang.reflect.Method.invokeNative(Native Method)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
java.lang.reflect.Method.invoke(Method.java:507)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
12-16 14:06:55.050: E/AndroidRuntime(19734):    at 
dalvik.system.NativeStart.main(Native Method)

Original comment by shameus....@gmail.com on 16 Dec 2012 at 7:12

GoogleCodeExporter commented 8 years ago
I really need related code sections to help you. 

Original comment by mathieu....@gmail.com on 17 Dec 2012 at 9:07

GoogleCodeExporter commented 8 years ago
I believe the buildRoadOverlay crash is fixed. The code was using the default 
OSMRoadManager. I changed the directions source to the MapQuestRoadManager and 
it's not crashing. It could be that the OSM road manager was returning bogus 
data perhaps. 

Thanks for your help.

Original comment by shameus....@gmail.com on 18 Dec 2012 at 2:03

GoogleCodeExporter commented 8 years ago
To avoid risk of race conditions, more synchronize sections have been 
implemented in ItemizedOverlayWithBubble in osmbonuspack v3.1. 
I now set the issue to Fixed. 

Original comment by mathieu....@gmail.com on 10 Jan 2013 at 10:05