Unity 5 RC1 and il2cpp build

Hi. I am evaluating A* Pathfinding for a new project. Build a sample scene including Behavior Designer, and all works well on the Editor/Game view. And also works great when I build for iOS using the Mono backend.
However, if I switch to the il2cpp backend (needed for 64 bit builds) then the path finding does not work. It simply fails silently, as if no path has been calculated or created.
To isolate the issue I built the PointGraphExample scene. Same results here: works if built with mono scripting, fails when I use il2cpp.
When building with il2cpp I got three warnings, and they seem to indicate bad code is being generated by the converter. So it is probably a Unity bug, I will report it to them as well. Just for completeness, here is a snippet of the code generated and the error reported:

// System.Void AstarPath::FloodFill(Pathfinding.GraphNode,System.UInt32)
extern MethodInfo AstarPath_FloodFill_m281_MethodInfo;
void AstarPath_FloodFill_m281 (AstarPath_t43 * __this, GraphNode_t21 * ___seed, uint32_t ___area){
Stack1_t73 * V_0 = {0};
_il2cpp_strinit_s_21();
{
if (___area <= ((int32_t)131071))
{
goto IL_0025;
}
}
{
uint32_t L_0 = ((int32_t)131071);
Object_t1 * L_1 = Box(InitializedTypeInfo(&UInt32_t1057_il2cpp_TypeInfo), &L_0);
IL2CPP_RUNTIME_CLASS_INIT((&String_t46_il2cpp_TypeInfo));
String_t46* L_2 = String_Concat_m3916(NULL /static, unused/, _str_i_4b, L_1);
Debug_LogError_m3914(NULL /static, unused/, L_2);
return;
}

IL_0025:
{
if (___area >= 0)
{
goto IL_0037;
}
}
{
Debug_LogError_m3914(NULL /static, unused/, _str_i_4c);
return;
}

And it points to the line
if (___area >= 0)
With the error:
Semantic issue: comparison of unsigned expressions >=0 is always true.

This happens in two other places as well, both on the method.

// System.Void Pathfinding.Ionic.Crc.CRC32::UpdateCRC(System.Byte,System.Int32)
extern MethodInfo CRC32_UpdateCRC_m9434_MethodInfo;

The problem seems to be related to decompressing some serialized data during the initialization of A*Star. From the console:

Initialize engine version: 5.0.0f1 (8a4fe2379c5e)
Shader ā€˜Legacy Shaders/Self-Illumin/Diffuseā€™: fallback shader ā€˜Legacy Shaders/Self-Illumin/VertexLitā€™ not found
Caught exception when loading from zip
Pathfinding.Ionic.Zip.ZipException: Cannot read that as a ZipFile ā€”> Pathfinding.Ionic.Zip.ZipException: Bad date/time format in the zip file. (y(2015) m(2) d(2) h(-12) m(17) s(10))
at Pathfinding.Ionic.Zip.WriteDelegate.Invoke (System.String entryName, System.IO.Stream stream) [0x00000] in :0
at Pathfinding.Ionic.Zip.SharedUtilities.PackedToDateTime (Int32 packedDateTime) [0x00000] in :0
at Pathfinding.Ionic.Zip.ZipEntry.ReadDirEntry (Pathfinding.Ionic.Zip.ZipFile zf, System.Collections.Generic.Dictionary2 previouslySeen) [0x00000] in <filename unknown>:0 at Pathfinding.Ionic.Zip.ZipFile.ReadCentralDirectory (Pathfinding.Ionic.Zip.ZipFile zf) [0x00000] in <filename unknown>:0 at Pathfinding.Ionic.Zip.ZipFile.ReadIntoInstance (Pathfinding.Ionic.Zip.ZipFile zf) [0x00000] in <filename unknown>:0 at Pathfinding.Ionic.Zip.ZipFile.Read (System.IO.Stream zipStream, System.IO.TextWriter statusMessageWriter, System.Text.Encoding encoding, System.EventHandler1 readProgress) [0x00000] in :0
at Pathfinding.Ionic.Zip.ZipFile.Read (System.IO.Stream zipStream) [0x00000] in :0
at Pathfinding.Serialization.AstarSerializer.OpenDeserialize (System.Byte[] bytes) [0x00000] in :0
at Pathfinding.AstarData.DeserializeGraphs (System.Byte[] bytes) [0x00000] in :0
at Pathfinding.AstarData.DeserializeGraphs () [0x00000] in :0
at Pathfinding.AstarData.Awake () [0x00000] in :0
at AstarPath.Initialize () [0x00000] in :0
at AstarPath.Awake () [0x00000] in :0
at Replacements.Attribute.CheckParameters (System.Object element, System.Type attributeType) [0x00000] in :0
ā€” End of inner exception stack trace ā€”

Looking at the docs it looks like it might be a problem with the DotNetZip library. I tried removing it and uncommenting the #defines, but could not get very far. Hope that helps the investigation, I will continue debugging tomorrow.

Good news first: the problem is really in the DotNetZip conversion. So I could make it work on Unity 5->il2cpp builds by checking the ASTAR_NO_ZIP checkbox in the Optimizations tab, and recreating the graphs. Still get some warnings but they seem harmless, at least in my limited testing.
From what I could tell, this only works with the Pro version right now (which I just purchased, as I was going to use the asset anyway for this project). I tried to make it work by manually uncommenting the defines in the Free version, but there are some missing method definitions that I could not solve there. Hope this helps.

Regards,
Mauricio Piacentini

Hi

Unfortunately it seems to be a Unity bug. It generates incorrect code for the date parsing, I am about to submit a bug report to them now.
What you can try is to follow the Windows Phone instructions here: http://arongranberg.com/astar/docs/iphone.php (you seemed to have done most of the things already however).

IL2CPP seems to have a lot of obscure code generation bugs, so it might take some time before everything is stable.

Best regards,
Aron

I got it working with 5.0.0.f1 and A* Pro, with ASTAR_NO_ZIP. However, I had to keep the dontnetzip.dll in the resources folder: removing it (even if not used) caused other il2cpp errors that prevented compilation. Hopefully these will be ironed out as Unity 5 gets patched.

Regards,
Mauricio

Is this likely to be the final-ish solution? I have 43 levels that I would need to go through and rebuild the graphs on. I can do it, but i donā€™t want to if i donā€™t need toā€¦and would hate to have to do it twiceā€¦

@HaroldBalls

Hopefully Unity will make IL2CPP more stable such that using ASTAR_NO_ZIP will not be required. There is no technical reason for the zip library not to work, IL2CPP is just very buggy at the moment.

If you do rebuild all your graphs and a Unity upgrade fixes IL2CPP, you can still leave the zip library disabled if you want. Itā€™s not a large problem unless you are using cached startup with large graphs.

As some mobile platforms do not support zip compression anyway (even with Mono) I think I will just leave it disabled for now, for safety. This way I will not have to recreate graphs when porting as well.

hmmā€¦Iā€™m on 4.6.3, and the above isnā€™t workingā€¦has any of these solutions been tested in 4.x builds?

Could you elaborate on ā€œnot workingā€?

Sorry, Iā€™m editing this post because after reading it again, it made very little sense.

Iā€™m testing on a year old iPad air, and with Mono, everything works. with il2CPP, I see no errors, but there is no actual pathfinding happening on the device. I rebuilt all my graphs and am using ASTAR_NO_ZIP as well as all of the other mobile changes you suggest in the Docs.

ā€¦I also tested on an iPad mini3 tonight, and got the same result

not sure if this mean anything, but this comes up in the log at startup

Trying to load data from a newer version of the A* Pathfinding Project
Current version: 3.6 Data version: 3.6.255.255

Ben

Can you enable ASTAR_NO_ZIP in the free version?

@early73

ASTAR_NO_ZIP should work in the free version as well. However the optimizations tab is not enabled there so you will have to find the relevant scripts (search for ASTAR_NO_ZIP) and enable it.

@HaroldBalls
Hmā€¦ There is no version 3.6.255.255, so I would suspect that is an IL2CPP bug :frowning:
Do you think you could send it to Unity so that they could fix it?

Hey guys!

Can you find a solution for solve this bug? I mean A*PathFinding in 64bit iOS (with il2cpp),
I try ASTAR_NO_ZIP and I resolve exception with Pathfinding.Ionic.Zip.Reduced this OK
But next I got exception: No metadata found in serialized data. I repeat it happens on iOS with il2cpp !

How can fix this?
Thanks

Hi

After you have enabled ASTAR_NO_ZIP you will need to recreate all your graphs, have you done that?

Aron, Thanks for fast answer!

Yes, I recreate graphs and seems all ok but in Editor, when I build to devices I got an exception which I wrote above!

Ok. You said

Does that mean you have enabled ASTAR_NO_JSON or have you done something else?

Yes I enabled ASTAR_NO_JSON, and ASTAR_NO_ZIP also ASTAR_FAST_NO_EXCEPTIONS

Wellā€¦ this sounds like yet another unity IL2CPP bug which is hard for me to do anything about unfortunately.
Just to get some more information, you could try opening the SimpleZipReplacement.cs script and in the Read method, add some Debug.Log calls to log what things it actually contains.