Quantcast
Channel: Questions in topic: "il2cpp"
Viewing all articles
Browse latest Browse all 598

IL2CPP C# passed ref float[] to C++ can't get right result

$
0
0
Hi, i was trying to write a C++ .a lib for iOS IL2CPP , and try to pass a ref float[] to a C++ func. In C++ proj, i init the float[]'s element, and want to get the value in C# code, but in C# script i get the float[] length is 1,not what i passed to C++. eg: C# Script : [DllImport ("__Internal")] private static extern bool TestRef(ref float[] array); void Start() { Debug.LogError ("Before TestRef"); float[] a = new float[5]; for(int i = 0; i < a.Length; i++) i = -1; TestRef (ref a); Debug.LogError ("After TestRef : " + a.Length); for (int i = 0; i < a.Length; i++) Debug.LogError ("a[" + i + "] = " + a[i]); } C++ Plugin: bool TestRef(float*& a) { cout << "[Plugin] Begin" << endl; for (Int i = 0; i < 5; i++) { a[i] = i; } cout << "[Plugin] After" << endl; return true; } and after run this demo, i get After TestRef : 1 a[0] = 0 after google i got this : The il2cpp_codegen_marshal_array function simply returns a pointer to the existing managed array memory, that’s it! http://blogs.unity3d.com/cn/2015/07/02/il2cpp-internals-pinvoke-wrappers/ and i want to know how to get the right result: a = {0,1,2,3,4} and btw this code run everything ok at Mac, PC, iOS(not IL2CPP) so i believe it is something about IL2CPP thanks all ~

Viewing all articles
Browse latest Browse all 598

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>