dji-sdk / Mobile-SDK-iOS

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

[BUG][M300] SDKCache thread - BAD_ACCESS #540

Closed GregCornis closed 1 year ago

GregCornis commented 1 year ago

We've been using a Matrice 300 with a custom iPad app for months, but suddenly the SDK started crashing every time the USB was connected to the remote.
The error is weird : it happens in a different thread (named SDKCache) because of a EXC_BAD_ACCESS (code=1, adress=0x0), so I'm guessing it's a NullPointerException ?
This bug happens right after the registration (calling DJISDKManager.startConnectionToProduct()).

The Sample App has the same crash, so it's likely not our code. Moreover, the app doesn't crash with a Mavic 2 Pro.
I factory reset the Smart RC and removed the logs on the aircraft, without any change.
I also tried a different iPad / cable / RC.

Any help would be greatly appreciated, this is preventing us from using the M300 at all.

Capture d’écran 2022-10-26 à 12 07 10
GregCornis commented 1 year ago

Problem is still here with SDK 4.16.2

DJI-William commented 1 year ago

It does not happen in our end, so it this problem also occurs in iOS 4.16.1 for you? 1

GregCornis commented 1 year ago
Thanks for the quick reply. Yes the issue happens for both versions. Here are the screenshots at the moment the app crashes:
IMG_0430 IMG_0429
GregCornis commented 1 year ago

I'm not sure if it is related but the LED appear red on both remotes, and I sometimes need to plug the cable off then on for the connection to happen

DJI-William commented 1 year ago

Are you using Object-C or Swift demo?

GregCornis commented 1 year ago

Swift

DJI-William commented 1 year ago

Swift demo has some problem, maybe try Object-C demo. We just update the demo yesterday, you can clone the latest code. What do you mean by red LEDs for bot remotes? You should only have a single controller.

GregCornis commented 1 year ago

I tried the Obj-C version (from latest commit 071cd3e), again with the same crash when I click "Register APP".

I meant this LED : IMG_20221027_104456

I'm not using two RC at the same time, but I thought the problem might be due to one of them so I tested with both, without any difference

DJI-William commented 1 year ago

The LED will not make this effect, it is very hard to tell what happens through this. The question is you havn't change the app and what conditions has changed to make this happened, we don't know about that yet. The code hasn't change, but it starts crashing.

GregCornis commented 1 year ago

Yes it's really weird, because I was developping the app and it worked fine, then I changed one line of code completely unrelated to the SDK, and the bug appeared. Do you know what the SDKCache Thread is doing ?

GregCornis commented 1 year ago

I see something strange in the logs, could it be related ?

2022-10-27 11:55:43.888443+0200 DJISDKSwiftDemo[1257:99826] open on /var/mobile/Containers/Data/Application/CA1CC13F-233B-40A7-A7C8-43152FFAA48B/Library/.space_db/flysafe_areas_djigo_en.db: No such file or directory
2022-10-27 11:55:44.638202+0200 DJISDKSwiftDemo[1257:100114] fopen failed for data file: errno = 2 (No such file or directory)
2022-10-27 11:55:44.638295+0200 DJISDKSwiftDemo[1257:100114] Errors found! Invalidating cache...
2022-10-27 11:55:45.328270+0200 DJISDKSwiftDemo[1257:99826] SDK Registered with error 
DJI-William commented 1 year ago

It seems like missing a database. Will the SDK successfully register without connecting to RC? Just only on the iPad?

GregCornis commented 1 year ago

Yes the app works fine as long as no device is plugged in, with a successful registration. It's not related to the ipad either as the bug happens with a different one too. After googling, it seems that the fopen failed for data file is related to Metal API and probably unrelated. I believe it's been there all along.

Any idea what the SDK is doing in the SDKCache thread?

DJI-William commented 1 year ago

SDKCache thread is the thread that operate the DJIKeys. E.g. If you call a SDK method, it will operate the DJI Key in SDKCache thread.

GregCornis commented 1 year ago

Ok thanks. Do you have any idea what could be causing this issue, or how to resolve it ? Or what test wa can perform to understand the source ?

DJI-William commented 1 year ago

Is it possible to get the crash log for us? We would like to see where and which function crashes.

GregCornis commented 1 year ago

Sure, how do I do that ? As I mentionned already, it happens in a different thread, so I don't have a stack trace for you. I can only show the assembly line that crashes the code, which is the image I've put in the description above

DJI-William commented 1 year ago

After the crash happens, connect your mobile device to the Xcode, in Xcode->window->devices and simulators->view device logs, find the corresponded log for your app at the crash time and export.

DJI-William commented 1 year ago

Even look at the log, we cannot guarantee the issue is fix. Perhaps you can try connect your aircraft and RC to the Assistant 2 to re-download and install the latest firmware and try again.

GregCornis commented 1 year ago

Here is the crash report, as I downloaded it from XCode.

DJISampleApp_M300_crash.crash.zip

Capture d’écran 2022-11-02 à 12 13 11

h.crash.zip)

And here are the full logs from the console

2022-11-02 12:11:09.887073+0100 DJISDKSwiftDemo[5288:410977] IAPAppRegisterClient: capabilities 0x8020
2022-11-02 12:11:09.887217+0100 DJISDKSwiftDemo[5288:410977] IAPAppRegisterClient: __eaClientRegisterediapd 0 -> 1
2022-11-02 12:11:09.887263+0100 DJISDKSwiftDemo[5288:410977] IAPAppRegisterClient: __eaClientRegisterediap2d 0 -> 1
2022-11-02 12:11:09.887578+0100 DJISDKSwiftDemo[5288:410977] IAPDHasLaunched: kIAPAvailableNotification iapdAvailableState 100 -> 0
2022-11-02 12:11:09.887654+0100 DJISDKSwiftDemo[5288:410977] IAPAppRegisterClient: __eaiapdHasClientID 0, IAPDHasLaunched 0
2022-11-02 12:11:09.888006+0100 DJISDKSwiftDemo[5288:410977] IAP2DHasLaunched: kIAP2AvailableNotification iap2dAvailableState 100 -> 0
2022-11-02 12:11:09.888063+0100 DJISDKSwiftDemo[5288:410977] IAPAppRegisterClient: __eaiap2dHasClientID 0, IAP2DHasLaunched 0
2022-11-02 12:11:09.888262+0100 DJISDKSwiftDemo[5288:410977] IAPAppRegisterClient: registerWasSuccessful 0
2022-11-02 12:11:09.888620+0100 DJISDKSwiftDemo[5288:410977] -[EAAccessoryManager _initFromSingletonCreationMethod] initializing (0x282aec3c0) with uuid 1BEBA3E8-AC94-44FC-8518-33C86771CC7A
2022-11-02 12:11:09.888686+0100 DJISDKSwiftDemo[5288:410977] -[EAAccessoryManager _initFromSingletonCreationMethod] isRunningOnMac
2022-11-02 12:11:09.893740+0100 DJISDKSwiftDemo[5288:410977] initialConnectedAccessories count 0
2022-11-02 12:11:09.893793+0100 DJISDKSwiftDemo[5288:410977] _connectedAccessories (0)
2022-11-02 12:11:09.893841+0100 DJISDKSwiftDemo[5288:410977] Done attaching initialConnectedAccessories
2022-11-02 12:11:09.893903+0100 DJISDKSwiftDemo[5288:410977] IAPAppConnectedAccessories: __eaClientHasCheckedForConnectedAccessories 0 -> 1
2022-11-02 12:11:09.894191+0100 DJISDKSwiftDemo[5288:410977] IAPAppConnectedAccessories: IAPDHasLaunched 0, IAP2DHasLaunched 0
2022-11-02 12:11:09.895221+0100 DJISDKSwiftDemo[5288:410977] On: 1045 RegisteredForLocalNotifications Count: 1
2022-11-02 12:11:09.895281+0100 DJISDKSwiftDemo[5288:410977] Returning connectedAccessories count 0
2022-11-02 12:11:09.895330+0100 DJISDKSwiftDemo[5288:410977] Returning connectedAccessories count 0
2022-11-02 12:11:09.895850+0100 DJISDKSwiftDemo[5288:410977] Returning connectedAccessories count 0
2022-11-02 12:11:09.895930+0100 DJISDKSwiftDemo[5288:410977] Returning connectedAccessories count 0
2022-11-02 12:11:09.896003+0100 DJISDKSwiftDemo[5288:410977] Returning connectedAccessories count 0
2022-11-02 12:11:10.564741+0100 DJISDKSwiftDemo[5288:410977] SDK Registered with error 
2022-11-02 12:11:10.565445+0100 DJISDKSwiftDemo[5288:411305] Returning connectedAccessories count 0
2022-11-02 12:11:11.062615+0100 DJISDKSwiftDemo[5288:411280] Metal API Validation Enabled
2022-11-02 12:11:11.712937+0100 DJISDKSwiftDemo[5288:411334] Returning connectedAccessories count 0
2022-11-02 12:11:11.713137+0100 DJISDKSwiftDemo[5288:411336] Returning connectedAccessories count 0
2022-11-02 12:11:11.765044+0100 DJISDKSwiftDemo[5288:411339] Returning connectedAccessories count 0
2022-11-02 12:11:44.022544+0100 DJISDKSwiftDemo[5288:410977] CoreAccessories accessoryInfo for arrival = {
    ACCExternalAccessoryPPIDKey = "<null>";
    ACCExternalAccessoryPrimaryUUID = "EA5DA820-7E2C-44BD-84B0-B378976C9005";
    ACCExternalAccessoryProtocolDetailsKey =     {
        "com.dji.common" =         {
            ACCExternalAccessoryMatchAction = 1;
            ACCExternalAccessoryProtocolEndpointUUID = "24CBBBF7-CFB4-4684-A519-FCED0323764B";
            ACCExternalAccessoryProtocolIndex = 0;
            ACCExternalAccessoryProtocolType = 2;
            ACCExternalAccessorySessionUsesSocketInterfaceKey = 1;
        };
    };
    ACCExternalAccessoryRegionCodeKey = "<null>";
    IAPAppAccessoryCapabilitiesKey = 1;
    IAPAppAccessoryCertDataKey = "607 bytes";
    IAPAppAccessoryCertSerialNumberKey = "16 bytes";
    IAPAppAccessoryDockTypeKey = "";
    IAPAppAccessoryFirmwareRevisionKey = "V03.00.01.63";
    IAPAppAccessoryFirmwareRevisionPendingKey = "<null>";
    IAPAppAccessoryHardwareRevisionKey = "V01.02.03.02";
    IAPAppAccessoryManufacturerKey = DJI;
    IAPAppAccessoryModelNumberKey = "RM500-ENT";
    IAPAppAccessoryNameKey = "DJI Smart Controller Enterprise";
    IAPAppAccessoryProtocolsKey =     {
        "com.dji.common" = 0;
    };
    IAPAppAccessorySerialNumberKey = 1ZMBHC900300NW;
    IAPAppAccessoryTransportType = 8;
    IAPAppAccessoryVehicleInfoInitialDataKey =     {
    };
    IAPAppConnectionIDKey = 34903018;
}
2022-11-02 12:11:44.026836+0100 DJISDKSwiftDemo[5288:410977] _externalAccessoryConnected: userInfo {
    ACCExternalAccessoryPPIDKey = "<null>";
    ACCExternalAccessoryPrimaryUUID = "EA5DA820-7E2C-44BD-84B0-B378976C9005";
    ACCExternalAccessoryProtocolDetailsKey =     {
        "com.dji.common" =         {
            ACCExternalAccessoryMatchAction = 1;
            ACCExternalAccessoryProtocolEndpointUUID = "24CBBBF7-CFB4-4684-A519-FCED0323764B";
            ACCExternalAccessoryProtocolIndex = 0;
            ACCExternalAccessoryProtocolType = 2;
            ACCExternalAccessorySessionUsesSocketInterfaceKey = 1;
        };
    };
    ACCExternalAccessoryRegionCodeKey = "<null>";
    IAPAppAccessoryCapabilitiesKey = 1;
    IAPAppAccessoryCertDataKey = {length = 607, bytes = 0x3082025b 06092a86 4886f70d 010702a0 ... b43a944e a1003100 };
    IAPAppAccessoryCertSerialNumberKey = {length = 16, bytes = 0x284c29f3738f9201f61a2ec714498e76};
    IAPAppAccessoryDockTypeKey = "";
    IAPAppAccessoryFirmwareRevisionKey = "V03.00.01.63";
    IAPAppAccessoryFirmwareRevisionPendingKey = "<null>";
    IAPAppAccessoryHardwareRevisionKey = "V01.02.03.02";
    IAPAppAccessoryManufacturerKey = DJI;
    IAPAppAccessoryModelNumberKey = "RM500-ENT";
    IAPAppAccessoryNameKey = "DJI Smart Controller Enterprise";
    IAPAppAccessoryProtocolsKey =     {
        "com.dji.common" = 0;
    };
    IAPAppAccessorySerialNumberKey = 1ZMBHC900300NW;
    IAPAppAccessoryTransportType = 8;
    IAPAppAccessoryVehicleInfoInitialDataKey =     {
    };
    IAPAppConnectionIDKey = 34903018;
}
2022-11-02 12:11:44.027224+0100 DJISDKSwiftDemo[5288:410977] For DJI Smart Controller Enterprise - 34903018 (transport 8), Found initialVehicleInfoDictionary {
}
2022-11-02 12:11:44.027297+0100 DJISDKSwiftDemo[5288:410977] eaAccessory CoreAccessoryPrimaryUUID = EA5DA820-7E2C-44BD-84B0-B378976C9005
2022-11-02 12:11:44.027391+0100 DJISDKSwiftDemo[5288:410977] Added accessory connectionID 34903018, UUID EA5DA820-7E2C-44BD-84B0-B378976C9005
2022-11-02 12:11:44.027493+0100 DJISDKSwiftDemo[5288:410977] On: 1550 Accessory Connected with UUID EA5DA820-7E2C-44BD-84B0-B378976C9005 connectionID 34903018 createdByCoreAccessories 1. RegisteredForLocalNotifications Count: 1
2022-11-02 12:11:44.027626+0100 DJISDKSwiftDemo[5288:411278] On: 1589 Accessory Connected. InternalNotPresentIniAPAccArray: 0
2022-11-02 12:11:44.027714+0100 DJISDKSwiftDemo[5288:410977] On: 1614 Posting EA DidConnect Notification for Accessory with UUID: EA5DA820-7E2C-44BD-84B0-B378976C9005 connectionID 34903018 createdByCoreAccessories 1
2022-11-02 12:11:45.033743+0100 DJISDKSwiftDemo[5288:411305] Returning connectedAccessories count 1
2022-11-02 12:11:45.034107+0100 DJISDKSwiftDemo[5288:411336] Returning connectedAccessories count 1
2022-11-02 12:11:45.034445+0100 DJISDKSwiftDemo[5288:411334] Returning connectedAccessories count 1
2022-11-02 12:11:45.034736+0100 DJISDKSwiftDemo[5288:411339] Returning connectedAccessories count 1
2022-11-02 12:11:45.045222+0100 DJISDKSwiftDemo[5288:411339] accessoryd sessionResult = 1, useSocketInterace = 1, sessionID = 0x34
2022-11-02 12:11:45.045408+0100 DJISDKSwiftDemo[5288:411339] socketPath from app = /var/mobile/Library/ExternalAccessory/ea.4989905789723005288
2022-11-02 12:11:45.056961+0100 DJISDKSwiftDemo[5288:411299] upgrade component: 1107, server_version: , device_version: , state: 255
2022-11-02 12:11:45.057793+0100 DJISDKSwiftDemo[5288:411299] upgrade component: 1107, server_version: , device_version: , state: 255
2022-11-02 12:11:45.058064+0100 DJISDKSwiftDemo[5288:411299] upgrade component: 1209, server_version: , device_version: , state: 255
2022-11-02 12:11:45.058384+0100 DJISDKSwiftDemo[5288:411299] upgrade component: 1209, server_version: , device_version: , state: 255
2022-11-02 12:11:45.063151+0100 DJISDKSwiftDemo[5288:410977] Product is connected but DJISDKManager.product is nil -> something is wrong
2022-11-02 12:11:45.201574+0100 DJISDKSwiftDemo[5288:411299] upgrade component: 1107, server_version: , device_version: , state: 2

I have already reinstalled the latest firmware, without a change. Can we agree that this bug is not caused by us but is related to the hardware / firmware ? The stack trace from above was obtained from the DJI Sample App (Swift version), without changing one line of code

DJI-William commented 1 year ago

Try under DJI Pilot, reset the RC Settings and set C1 and C2 to undefined. Seems to be some firmware issues on the M300 RC.

GregCornis commented 1 year ago

Thanks, problem solved by setting the buttons to undefined. Related issue on DJI's forum here.