Few cents about my commits

Framework target: EXC_BAD_ACCESS on NPE in try-catch block

|

Application with RoboVM target crashes with EXC_BAD_ACCESS, investigation shows that this happens on null pointer exception (NPE) that enclosed in corresponding try-catch block and shall not break away? Already covered in Tutorial: Crash Reporters and java exceptions.
Root case is same – signals.
Solution is same – use Signals.installSignals.
Post bellow describes how to deal with it and introduces changes into framework template.

API for host application to Signals.installSignals

To obey RoboVM’s rules host (objc or swift) application shall has access to Signals.installSignals. Adding it to ‘SampleSDK’ interface of sample application:

public final class Api {
    /**
     * this protocol is main class protocol that root entry point to SDK
     */
    interface SampleSDK extends ObjCProtocol {
        ...

        /**
         * installs Signal handlers of main application
         * Host project shall install all signal handlers inside in installer callback implementation
         * This will allow RoboVM keeps own signal handlers and handle NPE
         * @param installer block were all crash analytics initialization shall happen
         */
        @Method void installSignals(@Block Runnable installer);

        ...
    }
}

Its implementation is straight forward:

public class SampleSDKImpl extends NSObject implements Api.SampleSDK {
    ...

    @Override
    public void installSignals(@Block Runnable installer) {
        Signals.installSignals(installer::run);
    }
}

Changes to host application

Host application shall install all crash reporters inside installer block:

- (BOOL)application:(UIApplication * )application didFinishLaunchingWithOptions:(NSDictionary * )launchOptions {
    // Override point for customization after application launch.

    // testing RoboVM framework
    SampleSDK* sdk = SampleSDKInstance();
    [sdk installSignalHandlers:^{
        [[Fabric sharedSDK] setDebug:true];
        [[Crashlytics sharedInstance] setDebugMode:true];
        [Fabric with:@[[Crashlytics class]]];
    }];

    return YES;
}

RoboVM’s framework template was updated with same changes with commit, samples updated with another commit.
Related:

Comments