EXC_BAD_ACCESS when call method with Custom Type from Unity to iOS

50 views Asked by At

I try to build Unity to iOS.

And I have a method call from Unity to iOS,

I can see the details when I hover my mouse on the variable, but when I call the variable, It throw EXC_BAD_ACCESS.

Why? Any suggestion.

Here is the code:

Unity call:

// call
saveLoginConfig(config);


[DllImport("__Internal")]
private static extern void saveLoginConfig(LinLoginConfig config);

Unity object

    [Serializable]
    public struct LinLoginConfig
    {
        public bool haveEmail;
    }

ios bridge

extern void saveLoginConfig(const LinLoginConfig &config) {
    NSLog(@"saveLoginConfig haveEmail0"); // line1
    NSLog(@"saveLoginConfig haveEmail1:%@", &config); // line2
}

ios object

@interface LinLoginConfig : NSObject

@property(nonatomic, assign) bool haveEmail;

@end

At breakpoint: enter image description here I can see the detail.

throw: enter image description here

Why it happended? help~

Alternative plan

It maybe not a best Solution, but it works:

just declare the Custom Type in Objective-C++ file, not in Objective-C file.

like this:

extern "C" {

class CustomType {
public:
    bool haveEmail;
    ...
};

}

And it works.

1

There are 1 answers

0
Fan Applelin On

Alternative plan

It maybe not a best Solution, but it works:

just declare the Custom Type in Objective-C++ file, not in Objective-C file.

like this:

extern "C" {

class CustomType {
public:
    bool haveEmail;
    ...
};

}

And it works.