Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28415] iOS: KrollBridge no longer exposes "modules" method as of 10.0.0

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2021-11-02T18:59:41.000+0000
Affected Version/sRelease 10.0.0
Fix Version/sn/a
ComponentsiOS
Labelscrash, ios, modules
ReporterHans Knöchel
AssigneeJoshua Quick
Created2021-04-11T10:01:07.000+0000
Updated2021-11-02T18:59:41.000+0000

Description

This took us days to track down: There are crashes related to setters in modules built with SDK 9.x when running in an app with SDK 10. The following selector has been used (accessed via via.canDrag = true):
- (void)setCanDrag:(NSNumber *)value
The full method can be found [here](https://github.com/hansemannn/titanium-drag-and-drop/blob/master/ios/Classes/TiUIViewProxy%2BDragAndDrop.m#L15-L29). The crash is:
[DEBUG] -[__NSCFString count]: unrecognized selector sent to instance 0x7f83dc335000
[DEBUG] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString count]: unrecognized selector sent to instance 0x7f83dc335000'
[DEBUG] *** First throw call stack:
[DEBUG] (
[DEBUG]         0   CoreFoundation                      0x00007fff20421af6 __exceptionPreprocess + 242
[DEBUG]         1   libobjc.A.dylib                     0x00007fff20177e78 objc_exception_throw + 48
[DEBUG]         2   CoreFoundation                      0x00007fff204306f7 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
[DEBUG]         3   CoreFoundation                      0x00007fff20426036 ___forwarding___ + 1489
[DEBUG]         4   CoreFoundation                      0x00007fff20428068 _CF_forwarding_prep_0 + 120
[DEBUG]         5   TitaniumKit                         0x00000001090e19f5 -[TiScriptError formattedNativeStack] + 133
[DEBUG]         6   TitaniumKit                         0x00000001090e18fb -[TiScriptError description] + 1127
[DEBUG]         7   Foundation                          0x00007fff2084c37a _NSDescriptionWithLocaleFunc + 82
[DEBUG]         8   CoreFoundation                      0x00007fff203bae0d __CFStringAppendFormatCore + 12102
[DEBUG]         9   CoreFoundation                      0x00007fff203bc8a1 _CFStringCreateWithFormatAndArgumentsReturningMetadata + 145
[DEBUG]         10  CoreFoundation                      0x00007fff203bc80a _CFStringCreateWithFormatAndArgumentsAux2 + 20
[DEBUG]         11  TitaniumKit                         0x00000001090a3f3d TiLogMessage + 175
[DEBUG]         12  TitaniumKit                         0x00000001090e0eb0 -[TiExceptionHandler reportScriptError:] + 74
[DEBUG]         13  TitaniumKit                         0x00000001090cdd9e TiBindingEventProcess + 731
[DEBUG]         14  TitaniumKit                         0x00000001090ef223 -[KrollContext invoke:] + 109
[DEBUG]         15  TitaniumKit                         0x00000001090ef296 -[KrollContext enqueue:] + 93
[DEBUG]         16  TitaniumKit                         0x00000001090f6640 TiBindingRunLoopEnqueue + 77
[DEBUG]         17  TitaniumKit                         0x00000001090f4d45 -[TiProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 187
[DEBUG]         18  TitaniumKit                         0x00000001090d5b08 -[TiViewProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 224
[DEBUG]         19  TitaniumKit                         0x00000001090f4b3b -[TiProxy fireEvent:withObject:propagate:] + 76
[DEBUG]         20  libdispatch.dylib                   0x00007fff2010532f _dispatch_call_block_and_release + 12
[DEBUG]         21  libdispatch.dylib                   0x00007fff20106508 _dispatch_client_callout + 8
[DEBUG]         22  libdispatch.dylib                   0x00007fff20112ff7 _dispatch_main_queue_callback_4CF + 1045
[DEBUG]         23  CoreFoundation                      0x00007fff2038fdbb __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
[DEBUG]         24  CoreFoundation                      0x00007fff2038a63e __CFRunLoopRun + 2685
[DEBUG]         25  CoreFoundation                      0x00007fff203896d6 CFRunLoopRunSpecific + 567
[DEBUG]         26  GraphicsServices                    0x00007fff2c257db3 GSEventRunModal + 139
[DEBUG]         27  UIKitCore                           0x00007fff24696cf7 -[UIApplication _run] + 912
[DEBUG]         28  UIKitCore                           0x00007fff2469bba8 UIApplicationMain + 101
[DEBUG]         29  Lambus                              0x0000000106d8693b main + 1115
[DEBUG]         30  libdyld.dylib                       0x00007fff2025a3e9 start + 1
[DEBUG] )
The same works fine with SDK 9.3.2.GA and can be reproduced in our project shared with the team. I created a workaround in my module which can be seen [here](https://github.com/hansemannn/titanium-drag-and-drop/pull/4)

Comments

  1. Hans Knöchel 2021-04-13

    Can someone please address this? It's causing hundrets of crashes and it could be any module (along with the one already fixed)!
  2. Hans Knöchel 2021-04-14

    I have to calm a bit btw: It's still a prerelease :-)
  3. Christopher Williams 2021-04-14

    I'm not 100% certain the issue here is with the setter implementations. The underlying stack trace is obscured by our error handling tossing its own error while trying to handle it. I created a local branch and cherry-picked [~jquick]'s fix from https://github.com/appcelerator/titanium_mobile/pull/12721, then created an app, pasted in your module's example code into app.js, and launched its with the v1.0.0 zip on the releases page and a local build of SDK from master (10.1.0). This is what it threw:
       [ERROR] file:///app.js:33
       [ERROR] (null)
       [ERROR]            ^
       [ERROR] : [<KrollBridge 0x600003fdce40> valueForUndefinedKey:]: this class is not key value coding-compliant for the key modules.
       [ERROR]     at initializeDragAndDrop (file:///app.js:33:11)
       [ERROR]   
       [ERROR]     ti-example 0x000000010ed03401 +[TiDraganddropModule instance] + 93
       [ERROR]     ti-example 0x000000010ed02948 -[TiUIViewProxy(DragAndDrop) setCanDrag:] + 155
       [ERROR]     TitaniumKit0x000000010f040d52 -[KrollObject setValue:forKey:] + 410
       [ERROR]     TitaniumKit0x000000010f03f3ad KrollSetProperty + 360
       [ERROR]     JavaScriptCore 0x00007fff30d30919 _ZN3JSC16JSCallbackObjectINS_16JSNonFinalObjectEE3putEPNS_6JSCellEPNS_14JSGlobalObjectENS_12PropertyNameENS_7JSValueERNS_15PutPropertySlotE + 313
       [ERROR]     JavaScriptCore 0x00007fff31463b13 llint_slow_path_put_by_id + 3203
       [ERROR]     JavaScriptCore 0x00007fff30ccaf0d llint_entry + 38921
       [ERROR]     JavaScriptCore 0x00007fff30cc150f vmEntryToJavaScript + 216
       [ERROR]     JavaScriptCore 0x00007fff3136cda6 _ZN3JSC11Interpreter11executeCallEPNS_14JSGlobalObjectEPNS_8JSObjectERKNS_8CallDataENS_7JSValueERKNS_7ArgListE + 518
       [ERROR]     JavaScriptCore 0x00007fff315bd114 _ZN3JSC12profiledCallEPNS_14JSGlobalObjectENS_15ProfilingReasonENS_7JSValueERKNS_8CallDataES3_RKNS_7ArgListE + 164
       [ERROR]     JavaScriptCore 0x00007fff30d453d7 JSObjectCallAsFunction + 791
       [ERROR]     TitaniumKit0x000000010f059a71 TiBindingEventProcess + 686
       [ERROR]     TitaniumKit0x000000010f07af9f -[KrollContext invoke:] + 109
       [ERROR]     TitaniumKit0x000000010f07b012 -[KrollContext enqueue:] + 93
       [ERROR]     TitaniumKit0x000000010f0823eb TiBindingRunLoopEnqueue + 77
       [ERROR]     TitaniumKit0x000000010f080ac1 -[TiProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 187
       [ERROR]     TitaniumKit0x000000010f061808 -[TiViewProxy fireEvent:withObject:propagate:reportSuccess:errorCode:message:] + 224
       [ERROR]     TitaniumKit0x000000010f0808b7 -[TiProxy fireEvent:withObject:propagate:] + 76
       
    I think your code to try and access the shared singleton of the module instance is what's causing the issue (specifically https://github.com/hansemannn/titanium-drag-and-drop/blob/master/ios/Classes/TiDraganddropModule.m#L90-L94 ) - and it's to be expected, because KrollBridge does not have a modules property anymore. You were relying on some real internal knowledge there. Can you modify the module's init method to assign to some static singleton variable that the instance method could then return?
  4. Hans Knöchel 2021-04-14

    I did [this pull request](https://github.com/hansemannn/titanium-drag-and-drop/pull/4/files) to workaround the issues, in detail: - The "setCanDrag" and "setCanDrop" were property accessors (for "view.canDrag = true" and "view.canDrop"). If I leave it as-is, the methods could not be called - I'm not 100 % sure anymore if it was the setter in general or the underlaying "ENSURE_UI_THREAD". Therefore the PR did a bit more: - Move from setter to "real" method - Move from ENSURE_UI_THREAD to "TiThreadPerformOnMainThread" (incl. proper weak-selfs) - Move from \[TiApp.app.krollBridge valueForKey:@"modules"\] to \[TiApp.app valueForKey:@"modules"\] which (I hope) stays as-is for a while. I noticed that the naming of the module keys also changed from the identifier to the native class name ("ti.draganddrop" to "TiDraganddropModule") So to conclude, maybe I was testing with an old build for the setters, but I was pretty sure they haven't been called at all. Together with TIMOB-28419, I think we're running stable right now. So we could close this ticket for now and keep an eye on module compatibility.
  5. Christopher Williams 2021-04-14

    Testing with v1.0.0 against master branch, I generated this patch PR: https://github.com/appcelerator/titanium_mobile/pull/12724 Those changes seem to be enough for the example app to work. (Though I should note that the drop event listener being console.warn unbound did trigger an error. I had to change it to add the event listener as console.warn.bind(console)) So I don't think the setters are broken at all here.
  6. Christopher Williams 2021-04-14

    https://github.com/appcelerator/titanium_mobile/pull/12724
  7. Joshua Quick 2021-11-02

    The following PR replaces the above PR. It adds review feedback and solves conflicts. PR (master): https://github.com/appcelerator/titanium_mobile/pull/13161
  8. Joshua Quick 2021-11-02

    Closing as "invalid". We agreed that this is an undocumented API that should not be depended on.

JSON Source