dji-sdk / Mobile-SDK-iOS

DJI Mobile SDK for iOS: http://developer.dji.com/mobile-sdk/
Other
578 stars 255 forks source link

Immediate crash when accessing DJISDKVector3D #365

Closed adolfo closed 2 years ago

adolfo commented 4 years ago

Attempting to access any properties from a DJISDKVector3D value, e.g. from DJIFlightControllerParamAttitude, DJIFlightControllerParamVelocity, etc. results in an immediate crash.

Thread 0 name:
Thread 0 Crashed:
0   libswiftCore.dylib              0x00000001a110f3d4 swift_getAssociatedTypeWitnessSlowImpl(swift::MetadataRequest, swift::TargetWitnessTable<swift::I... + 256 (Metadata.h:550)
1   libswiftCore.dylib              0x00000001a110f3cc swift_getAssociatedTypeWitnessSlowImpl(swift::MetadataRequest, swift::TargetWitnessTable<swift::I... + 248 (Metadata.cpp:4643)
2   libswiftCore.dylib              0x00000001a110d990 swift_getAssociatedTypeWitness + 216 (CompatibilityOverride.def:164)
...

After some lengthy debugging, we discovered that DJISDKVector3D has an objc_runtime_name attribute which has an issue in Swift starting with Xcode 11.4 and still unresolved in Xcode 11.5.

//  DJISDKVector3D.h

/**
 *  A cartesian vector in 3D space.
 */

__attribute__((objc_runtime_name("74f47570-7b7b-11e8-bf4d-a860b61add44"))) 
@interface DJISDKVector3D : NSObject

This is listed in the Xcode 11.4 release notes:

Known Issues: If an Objective-C class is defined with the objc_runtime_name attribute and imported into Swift, Swift code may crash when trying to access the class. (60888835)

Workaround: Instead of using objc_runtime_name, define the class with its runtime name as the class name, and use a typedef to establish the desired source-level name:

The only workaround at the moment on our end is to rollback to an older Xcode release, however, Apple recommends to update DJISDKVector3D to use a typedef instead of the compiler attribute:

__attribute__((objc_runtime_name("Bar")))
@interface Foo: NSObject
@end

// Workaround
@interface Bar: NSObject
@end
typedef Bar Foo;
dji-dev commented 4 years ago

Agent comment from Luce Luo in Zendesk ticket #35150:

Dear Customer,

Thank you for contacting DJI. Sorry about it. Can you please tell me which MSDK version you are using?

Thanks,

Luce Luo DJI Dev Team

adolfo commented 4 years ago

@dji-dev we tested with 4.11 and 4.12. This issue should affect all MSDK versions that use the objc_runtime_name compiler attribute.

dji-dev commented 4 years ago

Agent comment from Luce Luo in Zendesk ticket #35150:

Dear Customer,

Thank you for contacting DJI. Sorry about it. I will report this issue to the engineer.

Thanks,

Luce Luo DJI Dev Team

adolfo commented 4 years ago

This issue has been reported as resolved in Xcode 11.4.1 release notes:

Fixed a crash that could occur in Swift code that imported an Objective-C class defined with the objc_runtime_name attribute. (60888835)

Have not tested this yet, though.