Uploaded image for project: 'Appcelerator Modules'
  1. Appcelerator Modules
  2. MOD-2441

Android: Ti.Map can't reuse existing annotations

    Details

    • Type: Improvement
    • Status: In Review
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Map
    • Labels:

      Description

      When you store annotations in a array and reasign them e.g. after filtering the current ti.map module will crash:

      Error:

      [WARN]  W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.model.Marker.remove()' on a null object reference
      [WARN]  W/System.err: 	at ti.map.TiUIMapView.addAnnotation(TiUIMapView.java:474)
      [WARN]  W/System.err: 	at ti.map.TiUIMapView.addAnnotations(TiUIMapView.java:489)
      [WARN]  W/System.err: 	at ti.map.TiUIMapView.updateAnnotations(TiUIMapView.java:498)
      [WARN]  W/System.err: 	at ti.map.TiUIMapView.propertyChanged(TiUIMapView.java:288)
      [WARN]  W/System.err: 	at org.appcelerator.kroll.KrollProxy.firePropertyChanged(KrollProxy.java:969)
      [WARN]  W/System.err: 	at org.appcelerator.kroll.KrollProxy.onPropertyChanged(KrollProxy.java:1058)
      [WARN]  W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
      [WARN]  W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:55)
      [WARN]  W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:41)
      [WARN]  W/System.err: 	at ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:166)
      [WARN]  W/System.err: 	at android.os.Handler.handleCallback(Handler.java:751)
      [WARN]  W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:95)
      [WARN]  W/System.err: 	at android.os.Looper.loop(Looper.java:173)
      [WARN]  W/System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6459)
      [WARN]  W/System.err: 	at java.lang.reflect.Method.invoke(Native Method)
      [WARN]  W/System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:938)
      [WARN]  W/System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
      

      Example:

      var Map = require('ti.map');
      var win = Titanium.UI.createWindow();
      var mapview = Map.createView({
      	bottom: 0,
      	right: 0,
      	width: Ti.UI.FILL,
      	height: Ti.UI.FILL,
      	rotateEnabled: true,
      	mapType: Map.MUTED_STANDARD_TYPE,
      	showsPointsOfInterest: false,
      	userLocation: true,
      });
      var ann = [];	// store annotations
       
      function setData() {
      	for (var i = 0; i < 10; i++) {
      		ann.push(Map.createAnnotation({
      			title: 'Title',
      			subtitle: 'subtitle',
      			latitude: Math.random() * 10 + 40,
      			longitude: Math.random() * 10,
      		}));
      	}
      	mapview.setAnnotations(ann);
      }
      setData();
       
       
      var btn = Ti.UI.createButton({
      	title: "add again",
      	bottom: 40
      });
      var btn2 = Ti.UI.createButton({
      	title: "add new",
      	bottom: 0
      });
      var btn3 = Ti.UI.createButton({
      	title: "set",
      	bottom: 80
      });
      btn.addEventListener("click", function() {
      	// remove and add existing annotation
      	mapview.removeAllAnnotations();
      	mapview.addAnnotation(ann[0]);
      })
       
      btn2.addEventListener("click", function() {
      	// create new annotation and set it
      	var anno = Map.createAnnotation({
      		title: 'Title',
      		subtitle: 'subtitle',
      		latitude: Math.random() * 10 + 40,
      		longitude: Math.random() * 10,
      	})
      	mapview.setAnnotations([anno]);
      })
       
      btn3.addEventListener("click", function() {
      	// reset existing annotation
      	mapview.setAnnotations([ann[0]]);
      })
      win.add(btn);
      win.add(btn2);
      win.add(btn3);
      win.add(mapview);
      win.open();
      
      

      Only the button "Add new" works. If I add or set an existing icon it will crash.

      Tested device/version:
      Android 7 (HTC A9)
      Ti SDK 7.2.0.GA
      Ti.Map 4.3.0

      Cause/Potential fix:
      This ticket TIMOB-23269 (which I can't access) added a super.release() which causes this problem. When I remove that line again the above example is working again. Not sure if that will lead to a memory problem again!

      This ticket https://jira.appcelerator.org/browse/AC-5582 should also be affected by that bug.

        Attachments

          Activity

            People

            • Assignee:
              ybanev Yordan Banev
              Reporter:
              michael Michael Gangolf
              Reviewer:
              Gary Mathews
            • Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Git Source Code