hansemannn / titanium-googlemaps

🗺 Use the Google Maps SDK in Titanium
Other
87 stars 26 forks source link

App crashes attempting to remove annotation from click event #144

Closed Brianggalvez closed 2 years ago

Brianggalvez commented 2 years ago

In my app I want to remove an annotation after a user clicks on it. What I do is pass the annotation param of the event to the mapView removeAnnotation method and the the app crashes with the following stack trace:

` Application Specific Information: terminating with uncaught exception of type NSException CoreSimulator 783.5 - Device: iPhone 12 Pro Max (3908B889-38B4-43B0-94E0-478F46A1D11E) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 12 Pro Max *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString count]: unrecognized selector sent to instance 0x7fbb4607fa00' dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode-12.5.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot abort() called

Last Exception Backtrace: 0 CoreFoundation 0x7fff20422faa exceptionPreprocess + 226 1 libobjc.A.dylib 0x7fff20193ff5 objc_exception_throw + 48 2 CoreFoundation 0x7fff20431d2f +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0 3 CoreFoundation 0x7fff204274cf __forwarding + 1455 4 CoreFoundation 0x7fff204297a8 _CF_forwarding_prep_0 + 120 5 TitaniumKit 0x110f24b8d -[TiScriptError formattedNativeStack] + 133 6 TitaniumKit 0x110f24a93 -[TiScriptError description] + 1127 7 Foundation 0x7fff2084fd9b _NSDescriptionWithLocaleFunc + 82 8 CoreFoundation 0x7fff203bbaf3 CFStringAppendFormatCore + 12167 9 CoreFoundation 0x7fff203bd589 _CFStringCreateWithFormatAndArgumentsReturningMetadata + 145 10 CoreFoundation 0x7fff203bd4f2 _CFStringCreateWithFormatAndArgumentsAux2 + 20 11 TitaniumKit 0x110ee467e TiLogMessage + 175 12 TitaniumKit 0x110f24048 -[TiExceptionHandler reportScriptError:] + 74 13 TitaniumKit 0x110f10d86 TiBindingEventProcess + 731 14 TitaniumKit 0x110f32407 -[KrollContext invoke:] + 109 15 TitaniumKit 0x110f3247a -[KrollContext enqueue:] + 93 16 TitaniumKit 0x110f39a89 TiBindingRunLoopEnqueue + 77 17 TitaniumKit 0x110f38208 -[TiProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 187 18 TitaniumKit 0x110f18a7b -[TiViewProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 224 19 TitaniumKit 0x110f37f1c -[TiProxy fireEvent:withObject:] + 72 20 BNEscolar 0x10fb69c8a -[TiGooglemapsView mapView:didTapMarker:] + 479 21 CoreFoundation 0x7fff20429a3c invoking + 140 22 CoreFoundation 0x7fff20426c6f -[NSInvocation invoke] + 305 23 CoreFoundation 0x7fff20426f02 -[NSInvocation invokeWithTarget:] + 70 24 BNEscolar 0x10f25d6aa -[GMSDelegateForward forwardInvocation:] + 99 25 CoreFoundation 0x7fff20427259 forwarding_ + 825 26 CoreFoundation 0x7fff204297a8 _CF_forwarding_prep_0 + 120 27 BNEscolar 0x10f26ad8d -[GMSMapView didTapMarker:] + 345 28 BNEscolar 0x10f286a19 -[GMSMarker wasTapped] + 57 29 BNEscolar 0x10f509719 -[GMSGestureHandlerView handleSingleTapGesture:] + 96 30 UIKitCore 0x7fff241eefe3 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 49 31 UIKitCore 0x7fff241f930d _UIGestureRecognizerSendTargetActions + 100 32 UIKitCore 0x7fff241f5b6e _UIGestureRecognizerSendActions + 294 33 UIKitCore 0x7fff241f4ea5 -[UIGestureRecognizer _updateGestureForActiveEvents] + 725 34 UIKitCore 0x7fff241e733f _UIGestureEnvironmentUpdate + 2717 35 CoreFoundation 0x7fff2038fd31 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 36 CoreFoundation 0x7fff2038a542 CFRunLoopDoObservers + 541 37 CoreFoundation 0x7fff2038aaf5 __CFRunLoopRun + 1129 38 CoreFoundation 0x7fff2038a1a7 CFRunLoopRunSpecific + 567 39 GraphicsServices 0x7fff2b874d85 GSEventRunModal + 139 40 UIKitCore 0x7fff246c14df -[UIApplication _run] + 912 41 UIKitCore 0x7fff246c639c UIApplicationMain + 101 42 BNEscolar 0x10f070e86 main + 1174 (main.m:77) 43 dyld 0x11a8634fe start + 462 `

hansemannn commented 2 years ago

It seems like a null-pointer in the didTapMarker: selector. It would probably already help if you add some NULL_IF_NIL() macros around the optional values.

Brianggalvez commented 2 years ago

mmm but the click event fires without problems. The error appears when I perform a removeAnnotation using as a parameter the annotation that the click event returns

hansemannn commented 2 years ago

Mhh okay, then the stack does not help much I think

ULSashido commented 2 years ago

I'm doing something somewhat similar. Keep a reference to all your Annotations, and delete that (you can use userObject.uuid as reference).

Brianggalvez commented 2 years ago

I'm doing something somewhat similar. Keep a reference to all your Annotations, and delete that (you can use userObject.uuid as reference).

I've tried this workaround but only works for the first annotation. After that, any annotation gets removed

ULSashido commented 2 years ago

Is it possible to send me a small snippet of your map click event that removes the annotation? I've just recently implemented something similar and it works fine for the first all all other annotations.

Brianggalvez commented 2 years ago

sorry guys, issue on my end. Even though, I've to implement the workaround of having an array of annotations because using the annotation param from click event caused the crash described in the original issue