- Home /
Android IL2CPP bulid crash MemoryStream deserialization
Hello! I'm developing casual game for Android and about to release first version.
But I stuck in terrible situation.
Google demand for 64bit apk, so I build as IL2CPP.
I get assetbundle from web server and it contains some binary data.
For binary data, I convert it as TextAsset.
Below is that code.
private IEnumerator GetAssetBundle()
{
UnityWebRequest www = UnityWebRequest.Get(hNetworkManager.serverURL);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Application.Quit();
}
else
{
string assetBundleDirectory = Application.persistentDataPath + "/AssetBundle";
string serialDataPath = Application.persistentDataPath + "/SerialData";
if (!Directory.Exists(assetBundleDirectory))
Directory.CreateDirectory(assetBundleDirectory);
if (!Directory.Exists(serialDataPath))
Directory.CreateDirectory(serialDataPath);
TextAsset[] textAssets;
AssetBundle assetBundle;
hLevel.SerialData[] serialDatas;
MemoryStream memoryStream;
BinaryFormatter formatter;
var studio = Instantiate(m_thumbnailStudio);
byte[] data = new byte[www.downloadHandler.data.Length - head];
System.Array.Copy(www.downloadHandler.data, head, data, 0, data.Length);
File.WriteAllBytes(Path.Combine(assetBundleDirectory, "levels.unity3d"), data);
assetBundle = AssetBundle.LoadFromFile(Path.Combine(assetBundleDirectory, "levels.unity3d"));
if (assetBundle == null)
{
//Debug.Log("Failed to load AssetBundle!");
yield break;
}
textAssets = assetBundle.LoadAllAssets<TextAsset>();
serialDatas = new hLevel.SerialData[textAssets.Length];
memoryStream = new MemoryStream();
formatter = new BinaryFormatter();
for (int i = 0; i < textAssets.Length; ++i)
{
memoryStream.Write(textAssets[i].bytes, 0, textAssets[i].bytes.Length);
memoryStream.Position = 0;
serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream);
memoryStream.SetLength(0);
}
memoryStream.Close();
var lastThemeColor = hColorManager.current.curColor;
for (int i = 0; i < serialDatas.Length; ++i)
studio.SaveThumbnail(serialDatas[i]);
hColorManager.current.SetTheme(lastThemeColor, true);
hSharedData.Initialize(serialDatas);
_loading.FirstLoading();
#endregion
}
}
Up there "serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream);" line occur exception like this. and build setting. I also test Mono version and it worked properly.
I have no idea to solve this. PLEASE SOMEBODY HELP ME!
Does this work with Android AR$$anonymous$$v7 (32-bit) builds with IL2CPP? Or is the problem only with 64-bit builds?
Can you submit this project with a bug report? This is not something we've seen before.
Your answer
Follow this Question
Related Questions
Using BinaryFormatter for deserialization - ArgumentException: method argument length mismatch 0 Answers
How to import the object from server to unity 2 Answers
[C#] Deserialization fails in Web Player 1 Answer
C# BinaryFormatter Deserialization Issues 1 Answer
Binary file Deserialize to list? 0 Answers