Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crash randomly when receive ERROR: null #352

Closed
Set2005 opened this issue Jan 10, 2015 · 25 comments
Closed

App crash randomly when receive ERROR: null #352

Set2005 opened this issue Jan 10, 2015 · 25 comments

Comments

@Set2005
Copy link

Set2005 commented Jan 10, 2015

I am using Ionic framework, my map view crash randomly with following errors, even home key doesn't work, had to wait for about a minute still it quit itself .

2015-01-10 23:00:31.270 App[1123:60b] ERROR: null
2015-01-10 23:00:31.271 App[1123:60b] ERROR: null
2015-01-10 23:00:31.271 App[1123:60b] ERROR: null

@wf9a5m75
Copy link
Member

Too much unclear. Please figure out the details in order to help.

@Set2005
Copy link
Author

Set2005 commented Jan 11, 2015

I am using version 1.2.4 and Ionic framework. The error occurs only on IOS when I switch to the map view, with following code

function initialize(div, coords, zoom) {
    if (!coords) {
        coords = $rootScope.currentLocation;
    }
    try {
        center = new plugin.google.maps.LatLng(coords.latitude, coords.longitude);
    } catch (e) {
        console.log("Plugin is not available!");
        return
    }

    if (!center) {
        throw new Exception("Map cannot init without a center!");
    }

    var mapDiv = document.getElementById(div);
    // Initialize the map plugin
    map = plugin.google.maps.Map.getMap(mapDiv);
    console.log("map initialized");
    map.setOptions({
        'controls': {
            'compass': true,
            'indoorPicker': true,
            'myLocationButton': true,
            'zoom': false
        },
        'gestures': {
            'scroll': true,
            'tilt': true,
            'rotate': true
        },
        'camera': {
            'latLng': center,
            'zoom': (zoom || 15)
        }
    });
    console.log("...........has map?")
    if (map) {
        map.moveCamera({
            'target': center,
            'zoom': (zoom || 15)
        });
        map.setClickable(true);
        map.clear();
    }
    return map;
}

@Set2005
Copy link
Author

Set2005 commented Jan 11, 2015

After the map is setup, I am looping through array of markers and call this function every time. Could this be the problem if I have over 300 markers?

function addMarker(latLng, title, icon, _callback) {
    markerOptions = {
        'position': latLng
    }
    if (title) {
        markerOptions['title'] = title;
    }
    if (icon) {
        markerOptions['icon'] = icon
    }
    //   'icon': 'www/img/icon-yellow.png'
    map.addMarker(markerOptions, function(marker) {
        if (_callback) {
            _callback(marker);
        }
        if (icon) {
            marker.setIcon({
                'url': icon
            });
        }
    });
}

@Set2005
Copy link
Author

Set2005 commented Jan 11, 2015

This is the loop

angular.forEach($scope.array, function(item) {
    if (item.coords) {
        var position = new plugin.google.maps.LatLng(item.coords.latitude, item.coords.longitude);
        mapService.addMarker(
            position,
            item.name,
            null,
            function(marker) {
                marker.addEventListener(plugin.google.maps.event.INFO_CLICK, function() {

                });
            });
    }
});

@wf9a5m75
Copy link
Member

At least, you should wait MAP_READY event.

function initialize(div, coords, zoom, callback) {
    var mapDiv = document.getElementById(div);
    // Initialize the map plugin
    map = plugin.google.maps.Map.getMap(mapDiv, {
        'controls': {
            'compass': true,
            'indoorPicker': true,
            'myLocationButton': true,
            'zoom': false
        },
        'gestures': {
            'scroll': true,
            'tilt': true,
            'rotate': true
        },
        'camera': {
            'latLng': center,
            'zoom': (zoom || 15)
        }
    });

    map.on(plugin.google.maps.event.MAP_READY, function() {
        console.log("map initialized");
        console.log("...........has map?")
        if (map) {
            map.moveCamera({
                'target': center,
                'zoom': (zoom || 15)
            });
            map.setClickable(true);
            map.clear();
        }

        callback(map);
    });
}

@Set2005
Copy link
Author

Set2005 commented Jan 15, 2015

Hi there,

I tried to put everything inside the init callback, but it still crashes randomly, I found the ERROR: null is caused by scope.homeStoreMap.setClickable(true);

Any idea?
Thanks

    $scope.homeStoreMap = plugin.google.maps.Map.getMap(document.getElementById("map_canvas"));
    $scope.homeStoreMap.on(plugin.google.maps.event.MAP_READY, function(myMap){
        var center = plugin.google.maps.LatLng($rootScope.currentLocation.latitude, $rootScope.currentLocation.latitude);
        console.log(".........check0")
        $timeout(function(){
            $scope.homeStoreMap.setOptions({
                'controls': {
                  'compass': true,
                  'indoorPicker': true,
                  'myLocationButton': true,
                  'zoom': false
                },
                'gestures': {
                  'scroll': true,
                  'tilt': true,
                  'rotate': true
                },
                'camera': {
                  'latLng': center,
                  'zoom': (zoom||15)
                }
            });

            $scope.homeStoreMap.moveCamera({
            'target': center,
            'zoom': 15
            });
        });


            $scope.homeStoreMap.setVisible(true);
            // $scope.homeStoreMap.setClickable(true);



        angular.forEach($scope.stores, function(store){
            // console.log(".........checkxx" + store.name)
            if (store.coords && store.coords.latitude && store.coords.longitude){
                $scope.homeStoreMap.addMarker({
                   'position': new plugin.google.maps.LatLng(store.coords.latitude, store.coords.longitude),
                   'title': store.name,

                });   
            }
        });
    }); 

@wf9a5m75
Copy link
Member

Error null is Cordova bug. It's.not related. Please show me the actual error log.

@Set2005
Copy link
Author

Set2005 commented Jan 15, 2015

There is no other error log at all, it crash all by chance when I switch betwee map views, maybe I can put something together in Github.

@wf9a5m75
Copy link
Member

Could you send me your apk file to my e-mail address directly?

@Set2005
Copy link
Author

Set2005 commented Jan 15, 2015

Do you mean Achieve IPA file? Because it only happens to IOS version. Just confirm the email address: wf9a5m75@gmail.com, will send it to you by today. I have donated some money for your effort. Thanks

@wf9a5m75
Copy link
Member

Oops, you are developing on iOS. Yes, send me your IPA file.

@hirbod
Copy link
Contributor

hirbod commented Jan 15, 2015

You can't transfer an IPA archive without the hassle of getting Masashi's UDID. After this, you need to register his UDID under developer.apple.com -> iOS -> Profiles/Certificates -> "Devices" and refetch the new provisioning profiles inside of Xcode. (Deselect team and reselect again). Choose Project -> Clean -> Project -> archive. If you choose TestFlight, export as Ad-Hoc development, if not, just as development. Just after this steps you can share an IPA file. Or use the Testflightapp but thats the same problem (just the install is a bit easier, works without iTunes when you rely on TestFlightApp)

@hirbod
Copy link
Contributor

hirbod commented Jan 15, 2015

HA!
I know why your app is crashing. It is exactly the same shit I have! I guess that you are loading your markers from remote, (http), am I right?

@wf9a5m75
Copy link
Member

Ah, yeah. I forgot about that. Thank you for point out.

I will reply my UUID when @jianbo send me your IPA file.

@hirbod
Copy link
Contributor

hirbod commented Jan 15, 2015

Bet a 100 bucks.... #337

if (icon) {
            marker.setIcon({
                'url': icon
            });
        }

When your url is a remote path, I'm sure this is the reason why your app crash..
@wf9a5m75: somehow, we need to figure out what's wrong there. I will submit my app in few days to the appstore (finally!!) and I hope that we can fix this problem till then.

@Set2005
Copy link
Author

Set2005 commented Jan 15, 2015

No man, my markers are loaded from array.

    angular.forEach($scope.stores, function(store){
            // console.log(".........checkxx" + store.name)
            if (store.coords && store.coords.latitude && store.coords.longitude){
                $scope.homeStoreMap.addMarker({
                   'position': new plugin.google.maps.LatLng(store.coords.latitude, store.coords.longitude),
                   'title': store.name,

                });   
            }
        });

@hirbod
Copy link
Contributor

hirbod commented Jan 15, 2015

And where are your marker images? Inside your www folder? Or on your server?

@Set2005
Copy link
Author

Set2005 commented Jan 15, 2015

No, I am using the default marker, no custom icon at all.

@hirbod
Copy link
Contributor

hirbod commented Jan 15, 2015

OK - so wrong alarm. Cause this is my problem. I could load 1000 markers without any problem, as long as I used the default marker. With remote marker images, my app crashed.

@Set2005
Copy link
Author

Set2005 commented Jan 15, 2015

I will send the IPA later when I got back, but is this the right thing to do? I am using Ionic, so when left a map view, I had to clear the map, and when you arrive at another map view, I am re-initialize the newmap view. this is what I do when left a view.

 $scope.$on('$destroy', function() {
    if ($scope.homeStoreMap){
      $scope.StoreMap.setVisible(false);
      $scope.StoreMap.removeEventListener();
      $scope.StoreMap.setClickable(false);
      $scope.StoreMap.clear();
    }
});

@hirbod
Copy link
Contributor

hirbod commented Jan 15, 2015

Actually it should be enough just to call $scope.StoreMap.remove() but sometimes you also need to call setClickable(false) but irc this bug was fixed some weeks ago.

@Set2005
Copy link
Author

Set2005 commented Jan 18, 2015

Im unable to reproduce the problem after reduce the marker to 40, and only able to reproduce once when there is 80 markers.

@xuzongque
Copy link

I'm not sure it will solve the crash problem, but I found the reason for the message "ERROR:null" printed out at console.

in - setIcon method of Marker.m

-(void)setIcon:(CDVInvokedUrlCommand *)command
{
  NSString *markerKey = [command.arguments objectAtIndex:1];
  GMSMarker *marker = [self.mapCtrl.overlayManager objectForKey:markerKey];

  CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT];
  [pluginResult setKeepCallbackAsBool:YES];
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

  // Create icon
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
  NSDictionary *iconProperty = [command.arguments objectAtIndex:2];
  [self setIcon_:marker iconProperty:iconProperty pluginResult:pluginResult callbackId:command.callbackId];
}

The [self.commandDelegate sendPluginResult] in the middle should be unnecessary, because the [self setIcon_] method in the end will also send results to cordova. There is another spot in -createMarker that is similar to this situation, at line 95.
Comment out those lines and there will be no "ERROR:null" in console anymore
Also, [self setIcon_] expects the iconProperty to be a NSDictionary *, so yes, need to pass in {url: '...'} from javascript.

@hirbod
Copy link
Contributor

hirbod commented Jan 29, 2015

You're right @xuzongque,

I think this is a copy & paste error. I guess this should be removed or wrapped around some if-else-statement @wf9a5m75

wf9a5m75 added a commit that referenced this issue Jan 29, 2015
@wf9a5m75
Copy link
Member

Thank you @xuzongque

wf9a5m75 added a commit that referenced this issue Jan 29, 2015
wf9a5m75 added a commit that referenced this issue Jan 29, 2015
wf9a5m75 added a commit that referenced this issue Mar 1, 2015
wf9a5m75 added a commit that referenced this issue Mar 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants