mapsplugin / cordova-plugin-googlemaps

Google Maps plugin for Cordova
Apache License 2.0
1.66k stars 916 forks source link

iOS app terminated by GMSThreadException when marker url isn't valid #2605

Closed eltaiguer closed 5 years ago

eltaiguer commented 5 years ago

I'm submitting a ... (check one with "x")

OS: (check one with "x")

cordova information: (run $> cordova plugin list)

com-badrit-base64 0.2.0 "Base64"
cordova-android-firebase-gradle-release 2.0.0 "cordova-android-firebase-gradle-release"
cordova-android-play-services-gradle-release 1.4.6 "cordova-android-play-services-gradle-release"
cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab"
cordova-plugin-buildinfo 2.0.2 "BuildInfo"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-customurlscheme 4.3.0 "Custom URL scheme"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-facebook4 3.2.0 "Facebook Connect"
cordova-plugin-googlemaps 2.5.3 "cordova-plugin-googlemaps"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 2.3.1 "cordova-plugin-ionic-webview"
cordova-plugin-request-location-accuracy 2.2.3 "Request Location Accuracy"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-telerik-imagepicker 2.2.2 "ImagePicker"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-universal-links-plugin 1.2.1 "Universal Links Plugin"
ionic-plugin-deeplinks 1.0.17 "Ionic Deeplink Plugin"
twitter-connect-plugin 0.6.0 "Twitter Connect"

If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly)

@ionic-native/core : ^4.11.0
@ionic-native/google-maps : ^4.9.1

Current behavior: Sometimes when adding markers with a custom icon, I get a message that it failed loading the url. Right after that I get the following message: Terminating app due to uncaught exception 'GMSThreadException', reason: 'The API method must be called from the main thread' If wrap the marker code with a try-catch, the app still crashes

Expected behavior: The try-catch block should catch the exception and the app shouldn't crash if it fails to load the marker url.

Related code, data or error log (please format your code or data): Xcode log

2019-04-22 20:02:53.933799-0300 Dishly[58382:3578682] [fail] url = https://s3.amazonaws.com/dishly/img/i/lot_of_shrimp_scampi/1_61689-thumb.jpg
2019-04-22 20:02:53.941674-0300 Dishly[58382:3578682] *** Terminating app due to uncaught exception 'GMSThreadException', reason: 'The API method must be called from the main thread'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000011029e1bb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x000000010f080735 objc_exception_throw + 48
    2   CoreFoundation                      0x000000011029e015 +[NSException raise:format:] + 197
    3   Dishly                              0x0000000109fce4c2 -[GMSOverlay setMap:] + 89
    4   Dishly                              0x0000000109ef621a __52-[PluginMarker setIcon_:iconProperty:callbackBlock:]_block_invoke.597 + 362
    5   Dishly                              0x0000000109ef8eb8 __53-[PluginMarker downloadImageWithURL:completionBlock:]_block_invoke_2 + 344
    6   CFNetwork                           0x000000010f9f3940 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
    7   CFNetwork                           0x000000010fa09b0c __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 172
    8   Foundation                          0x000000010eaedf9e __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
    9   Foundation                          0x000000010eaedea5 -[NSBlockOperation main] + 68
    10  Foundation                          0x000000010eaeac14 -[__NSOperationInternal _start:] + 689
    11  Foundation                          0x000000010eaf0c4b __NSOQSchedule_f + 227
    12  libdispatch.dylib                   0x00000001107fb595 _dispatch_call_block_and_release + 12
    13  libdispatch.dylib                   0x00000001107fc602 _dispatch_client_callout + 8
    14  libdispatch.dylib                   0x00000001107ff54d _dispatch_continuation_pop + 565
    15  libdispatch.dylib                   0x00000001107fe927 _dispatch_async_redirect_invoke + 859
    16  libdispatch.dylib                   0x000000011080d00a _dispatch_root_queue_drain + 351
    17  libdispatch.dylib                   0x000000011080d9af _dispatch_worker_thread2 + 130
    18  libsystem_pthread.dylib             0x0000000110bec6b3 _pthread_wqthread + 583
    19  libsystem_pthread.dylib             0x0000000110bec3fd start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Support this plugin activity

I appreicate if you give me a beer :beer: from here

wf9a5m75 commented 5 years ago

Can't access to https://s3.amazonaws.com/dishly/img/i/lot_of_shrimp_scampi/1_61689-thumb.jpg. All images must be public in order to access from this plugin.

Unfortunately, creating tons of waste code for try-catch is too much job for me. Please use this plugin as is.

eltaiguer commented 5 years ago

Yeah, I know, the thing is this kind of a piece of the bigger problem.

Here's what's happening although I can't really explain it. That url you can't access? I don't know where the addMarker method is getting it from. I have checked the urls I use by adding console logs to every call to addMarker, and that url should actually be: https://s3.amazonaws.com/dishly/img/d/i/lot_of_shrimp_scampi/1_61689-thumb.jpg (which is valid) somewhere between the addMarker method and the output log of [fail] url = https://s3.amazonaws.com/dishly/img/i/lot_of_shrimp_scampi/1_61689-thumb.jpg the url is missing a /d/ is the plugin doing any kind of processing on the urls?

wf9a5m75 commented 5 years ago

How did you write your code?

eltaiguer commented 5 years ago

You mean the code where I call the addMarker method?

for (const item of results) {
      const url = item.img;
      console.log(url);
      this.map.addMarker({
        icon: {
          url: url,
          size: {
            width: 50,
            height: 50
          }
        },
        position: {
          lat: item.loc[1],
          lng: item.loc[0]
        },
        info: item
      })
      .then((marker) => this.markerClicked(marker))
      .catch((error) => console.error(error));
    }
wf9a5m75 commented 5 years ago

Yeah, and please show me some results.

eltaiguer commented 5 years ago

results? what do you mean?

wf9a5m75 commented 5 years ago

for (const item of results) {

eltaiguer commented 5 years ago

oh yeah, sorry, my bad.

[
   {
      "dishId":"5936b43336329f0004849064",
      "name":"Shrimp Scampi",
      "descr":"Spinach, gnocchi, grilled ciabatta",
      "price":20,
      "url":"/d/Washington/Farmers_Fishers_Bakers/Shrimp_Scampi/5936b43336329f0004849064",
      "loc":[
         -77.05977648496628,
         38.901677080420264
      ],
      "img":"https://s3.amazonaws.com/dishly/img/d/i/lot_of_shrimp_scampi/1_61689-thumb.jpg",
      "photo":"https://s3.amazonaws.com/dishly/img/d/i/lot_of_shrimp_scampi/1_61689-thumb.jpg",
      "menu":"Lunch & Dinner",
      "submenu":"Seafood Catch",
      "venue":{
         "vId":"55e4b400b04efbe04a139b49",
         "name":"Farmers Fishers Bakers",
         "url":"/v/Farmers_Fishers_Bakers/55e4b400b04efbe04a139b49",
         "displayAddress":"3000 K St NW, Washington, D.C. 20007"
      },
      "rating":5,
      "ratingSort":5,
      "sort":"80-49990-Shrimp Scampi",
      "nbRatings":4
   },
   {
      "dishId":"57d4382a4bcc3f03006af910",
      "name":"Palak Chaat",
      "descr":"Crispy baby spinach, sweet yogurt, tamarind, date chutney",
      "url":"/d/Washington/Rasika_West_End/Palak_Chaat/57d4382a4bcc3f03006af910",
      "loc":[
         -77.04807937145233,
         38.90506478729127
      ],
      "img":"https://s3.amazonaws.com/dishly/img/d/i/palak_chaat/5_87014-thumb.jpg",
      "photo":"https://s3.amazonaws.com/dishly/img/d/i/palak_chaat/5_87014-thumb.jpg",
      "menu":"Tasting",
      "submenu":"Grand (Four Courses) - First Course",
      "venue":{
         "vId":"5612b561edb2c2b9500c7882",
         "name":"Rasika West End",
         "url":"/v/Rasika_West_End/5612b561edb2c2b9500c7882",
         "displayAddress":"1190 New Hampshire Ave NW, Washington, D.C. 20037"
      },
      "rating":4.2,
      "ratingSort":4.2,
      "sort":"80-41770-Palak Chaat",
      "nbRatings":21
   },
   {
      "dishId":"5a1360a160d21d000431418b",
      "name":"Margherita",
      "url":"/d/Washington/FoBoGro/Margherita/5a1360a160d21d000431418b",
      "loc":[
         -77.04815575565883,
         38.89737202606131
      ],
      "img":"https://s3.amazonaws.com/dishly/img/d/i/margarita_pizza/7_86167-thumb.jpg",
      "photo":"https://s3.amazonaws.com/dishly/img/d/i/margarita_pizza/7_86167-thumb.jpg",
      "menu":"Main (discovered items)",
      "submenu":"Food",
      "venue":{
         "vId":"5731d1ab1655d5aa84779ff4",
         "name":"FoBoGro",
         "url":"/v/FoBoGro/5731d1ab1655d5aa84779ff4",
         "displayAddress":"2140 F St NW, Washington, D.C. 20037"
      },
      "rating":4.1,
      "ratingSort":4.1,
      "sort":"80-40930-Margherita",
      "nbRatings":0
   },
   {
      "dishId":"57d2c78088910c030032e296",
      "name":"Uncle Buck's Beignets",
      "descr":"With raspberry, chocolate & caramel sauces",
      "price":9.5,
      "url":"/d/Washington/Founding_Farmers/Uncle_Buck_s_Beignets/57d2c78088910c030032e296",
      "loc":[
         -77.0445193853609,
         38.90057336898503
      ],
      "img":"https://s3.amazonaws.com/dishly/img/d/i/beignets/3_34948-thumb.jpg",
      "photo":"https://s3.amazonaws.com/dishly/img/d/i/beignets/3_34948-thumb.jpg",
      "menu":"Breakfast and Brunch Menu",
      "submenu":"Share Plates",
      "venue":{
         "vId":"55e4b400b04efbe04a139b52",
         "name":"Founding Farmers",
         "url":"/v/Founding_Farmers/55e4b400b04efbe04a139b52",
         "displayAddress":"1924 Pennsylvania Ave NW, Washington, D.C. 20006"
      },
      "rating":4.1,
      "ratingSort":4.1,
      "sort":"80-40700-Uncle Buck's Beignets",
      "nbRatings":8
   }
]
eltaiguer commented 5 years ago

Hi, is this going to be released?

wf9a5m75 commented 5 years ago

You can install this plug-in from this GitHub repository directly.

eltaiguer commented 5 years ago

I meant the commit you added with the fix

wf9a5m75 commented 5 years ago

You need to install from GitHub repository directly until I release next version.

eltaiguer commented 5 years ago

Cool, thanks 👍

wf9a5m75 commented 5 years ago

v2.6.1 has been released.