I’m using Unity v.5.3.6, and everything was OK, until one day I added some new classes to my project, and Xcode start throwing the following errors:
~my_path~/Classes/Native/Bulk_Assembly-CSharp_2.cpp:177:8: note: forward declaration of ‘Vector2U5BU5D_t2741383957’ struct Vector2U5BU5D_t2741383957; ^ ~my_path~/Classes/Native/Bulk_Assembly-CSharp_2.cpp:10983:213: error: member access into incomplete type ‘Vector2U5BU5D_t2741383957’ VirtActionInvoker1< Vector2_t3525329788 >::Invoke(19 /* System.Void System.Collections.Generic.List`1<UnityEngine.Vector2>::Add(!0) /, __this, ((Vector2_t3525329788 )(((((Vector2U5BU5D_t2741383957**)L_0)))->GetAddressAt(static_cast<il2cpp_array_size_t>(L_1))))); ^ ~my_path~/Classes/Native/Bulk_Assembly-CSharp_2.cpp:177:8: note: forward declaration of ‘Vector2U5BU5D_t2741383957’ struct Vector2U5BU5D_t2741383957; ^ 2 errors generated.
I cut down my project - all assets, textures, scenes, prefabs, postprocessor scripts, etc are removed (there are only *.cs files left), but the error is still here.
BUT When I remove any of *.cs files - error disappeared! It really looks like a black magic
Please advise, how can I find the reason of this error to avoid it now and ever after
This is certainly a bug on the Unity side, as IL2CPP should never generated C++ code that does not compile. It may be pretty difficult for you to track down the cause of this error, unfortunately. I suspect that we will need to debug the il2cpp.exe code generation step to determine how to correct it.
Can you submit a bug report and include the project that causes this issue? If so, please let me know the bug report number, and we’ll correct this. Thanks!
@JoshPeterson , Hi Josh. Were you able to take a look at the bug report I have submitted? It is preventing me from building to any platform that requires IL2CPP (All console platforms)
Thanks again for the bug report. I’ve started to investigate it now, and we’re working on a fix. In the meantime, you can work around this issue.
The problem is caused by the use of the in modifier on function arguments that are arrays. After I removed a few from the project in the bug report, I was able to get it to compile. I’ll respond via the bug report with specifics about the changes, but I wanted to mention it here for others who might see this.
I expect that we will be able to get this corrected in IL2CPP soon.
You have mentioned that we can remove “in” modifier but would that not cause the array to be passed by copying? ( I could be wrong … ). If so the code behaviour may be the same, but performance wise may not. Am I correct in this?
If it makes no difference at all, then I can just not use “in” modifier at all. Otherwise, I will bring it back once the bug has been addressed.
Even without the in modifier, the array will be passed by reference. Some arrays are copied when passed from managed to native code via p/invoke. But for a managed to managed method call like this, the array will not be copied.
A bit of additional information on this issue - it turns out that the code also must use the in modifier for an array type on a virtual method to trigger this bug in IL2CPP. If the method is not virtual, the bug will not occur.