Native map MapListenerEvent and getBoundingBox causing an error

22 views
Skip to first unread message

Thomas

unread,
Aug 8, 2018, 11:56:41 PM8/8/18
to CodenameOne Discussions
I use the native map cn1lib with a maplistener that, when the position of the map changed, performs a getBoundingBox() request on the map (to get the new bounding box of the displayed zone) and then use a third party database to request some elements into this zone.
The problem is that, when the map is dragged, the app sometimes fails during this process with the following error:

D/MyApplication( 5619): [EDT] 0:1:18,984 - Exception: java.lang.ArrayIndexOutOfBoundsException - length=0; index=0
W/System.err( 5619): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
W/System.err( 5619):    at com.codename1.ui.Form.pointerDragged(Unknown Source)
W/System.err( 5619):    at com.codename1.ui.Display.handleEvent(Unknown Source)
W/System.err( 5619):    at com.codename1.ui.Display.edtLoopImpl(Unknown Source)
W/System.err( 5619):    at com.codename1.ui.Display.invokeAndBlock(Unknown Source)
W/System.err( 5619):    at com.codename1.ui.Display.invokeAndBlock(Unknown Source)
W/System.err( 5619):    at com.codename1.impl.android.AndroidImplementation.runOnUiThreadAndBlock(Unknown Source)
W/System.err( 5619):    at com.codename1.googlemaps.InternalNativeMapsImpl.calcLatLongPosition(InternalNativeMapsImpl.java:1331)
W/System.err( 5619):    at com.codename1.googlemaps.InternalNativeMapsStub.calcLatLongPosition(InternalNativeMapsStub.java:265)
W/System.err( 5619):    at com.codename1.googlemaps.MapContainer.getCoordAtPosition(MapContainer.java:1477)
W/System.err( 5619):    at com.codename1.googlemaps.MapContainer.getBoundingBox(MapContainer.java:1366)
W/System.err( 5619):    at org.tbdlab.myapp.ui.components.map.MapWithParkings.getBoundingBox(MapWithParkings.java:253)
W/System.err( 5619):    at org.tbdlab.myapp.ui.components.map.ParkingsMap.fetchZoneParkings(ParkingsMap.java:85)
W/System.err( 5619):    at org.tbdlab.myapp.ui.components.map.ParkingsMap.access$000(ParkingsMap.java:33)
W/System.err( 5619):    at org.tbdlab.myapp.ui.components.map.ParkingsMap$1.mapPositionUpdated(ParkingsMap.java:55)
W/System.err( 5619):    at com.codename1.googlemaps.MapContainer.fireMapListenerEvent(MapContainer.java:1678)
W/System.err( 5619):    at com.codename1.googlemaps.MapContainer$7.run(MapContainer.java:1577)
W/System.err( 5619):    at com.codename1.ui.Display.processSerialCalls(Unknown Source)
W/System.err( 5619):    at com.codename1.ui.Display.edtLoopImpl(Unknown Source)
W/System.err( 5619):    at com.codename1.ui.Display.invokeAndBlock(Unknown Source)
W/System.err( 5619):    at com.codename1.ui.Display.invokeAndBlock(Unknown Source)

any idea of what might be the cause of this issue and how to fix it? 

Thomas

unread,
Aug 8, 2018, 11:58:07 PM8/8/18
to CodenameOne Discussions
Forgot to say that the error is happening on android. In the simulator this is OK.

Shai Almog

unread,
Aug 9, 2018, 12:34:57 AM8/9/18
to CodenameOne Discussions
This is triggered by invokeAndBlock nesting which can lead to bad situations like this. I suggest adding a small delay to make sure that panning finished before you check bounds and start fetching. If the user is still dragging his finger you'd end up filling the device network queue completely.

You can use a timer to do the request and if you get a new drag event just cancel and resubmit the timer.

We're also replacing some of the Map API's with asynchronous ones that are based on callbacks. These handle the communication with the native layer better.

Thomas

unread,
Aug 9, 2018, 12:48:12 AM8/9/18
to CodenameOne Discussions
I allready have my own queue for network calls that control that the same request is not performed twice. So user dragging his finger would not be an issue for the network queue here ;) . As for the invokeAndBlock method call, if I replace it with an assyncroneous call of the native Google map getProjection().fromScreenLocation() native function, it would fix the issue? (I already use my own fork of the CN1 native maps lib so it is really not an issue to perform the change for me)

Shai Almog

unread,
Aug 10, 2018, 12:51:28 AM8/10/18
to CodenameOne Discussions
Does your queue handle cases of 0.000001 movements that trigger hundreds of events?
If you have a fork I would suggest using more async API's. If you have code that would be valuable to the general community I would suggest using a pull request to submit it. This can help you align with our baseline and if there are bugs/issues/enhancements everyone can benefit.
Reply all
Reply to author
Forward
0 new messages