UnityInitApplicationNoGraphics cause EXC_BAD_ACCESS on IOS

  • Description

I have a workspace which integrated iOS with unity, it works good when i using Xcode 8.3.3, but error happened after i switch to Xcode 8 beta 3. So i create a new project to make a test.

  • Environments

Xcode 9 beta 3
Unity 5.6.2f1
Mac OSX Sierra 10.12.5 (16F73)

  • Operation
    I created a new Unity project, and created a new scene with one cube in it. Switch to iOS platform and build. It worked if i open Unity-iPhone.xcodeproj and run.

And I create a new workspace and a new project cuz i want to do some native operation, so i integrate iOS with unity according to This Link.

But when I run i after solve build error, it crash.

  • Code

AppDelegate

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window.backgroundColor = [UIColor redColor];
    self.unityController = [[UnityAppController alloc] init];
    [self.unityController application:application didFinishLaunchingWithOptions:launchOptions];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    [self.unityController applicationWillResignActive:application];
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    [self.unityController applicationDidEnterBackground:application];
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    [self.unityController applicationWillEnterForeground:application];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    [self.unityController applicationDidBecomeActive:application];
}


- (void)applicationWillTerminate:(UIApplication *)application {
    [self.unityController applicationWillTerminate:application];
}

- (UIWindow *)unityWindow {
    return UnityGetMainWindow();
}

- (void)showUnityWindow {
    [self.unityWindow makeKeyAndVisible];
}

- (void)hideUnityWindow {
    [self.window makeKeyAndVisible];
}

@end

ViewController

#import "ViewController.h"
#import "AppDelegate.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor blueColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"Show Unity" forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 100, 44);
    button.center = self.view.center;
    [button addTarget:self action:@selector(showUnity) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)showUnity {
    [(AppDelegate *)[UIApplication sharedApplication].delegate showUnityWindow];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

@sdullaghan Yeah I found solutions finally.

You can check this 1

If the link above not solve your problem, try add:

  • -DINIT_SCRIPTING_BACKEND=1
  • -DRUNTIME_IL2CPP=1

in Other C Flags of your project’s build settings.

Hi,
Unity 2018.3 and Xcode 11.5 I met this same issue.

When I build framework with Static Library Mach-O type, then this EXC_BAD_ACCESS error occured in UnityInitApplicationNoGraphics()

When Dynamic library, it’s not happened.

@jake-ruman did you fix this problem?

I added this pre-defined flags to “Other C Flags”, it didn’t resolve this issue.

Thank you.