博客> unity接iosSDK时,带返回值的函数调用产生崩溃
unity接iosSDK时,带返回值的函数调用产生崩溃
2018-11-09 16:24 评论:0 阅读:685 yc889840
ios 崩溃 sdk unity

当在unity层调ios sdk获取版本号的时候,报错:

malloc: *** error for object 0x1b78fdd: pointer being freed was not allocated

解决办法:

Unity层代码:

[DllImport ("__Internal")] private static extern string midasSdkGetVersion();

c代码:

if defined(__cplusplus)

extern "C"{

endif

const char* midasSdkGetVersion()

{

   if (midasSdk == NULL) {

        midasSdk = [[MidasSdkConnector alloc] init];

    }

   return [midasSdk getVersion];

}

if defined(__cplusplus)

}

endif

改为:

const char* midasSdkGetVersion()

{

    if (midasSdk == NULL) {

       midasSdk = [[MidasSdkConnector alloc] init];

    }

   NSString * str = [midasSdk getVersion];

   char * version = (char *)malloc(strlen([str UTF8String]) + 1);

    strcpy(x, [str UTF8String]);

    return version;

}

收藏
0
sina weixin mail 回到顶部