Hello,
I have already filed a bug case #690754 but thought I would post what I’m seeing here in case others are having the same problem.
Looks like nested classes inside a protobuf-net class causes a crash when deserialising with only Unity 4.6.4 patch 1 & patch 2.
Unity 4.6.3 versions don’t show this problem.
Some notes:
- moved the partial class into a separate file but still nested, still results in a crash
- class being serialised does not contain instance of class A other than definition of class
- crash occurs on both device and simulator
Thanks.
Jack
Class looks something like this:
namespace YourProject
{
[global::System.Serializable, global::protoBuf.ProtoContract(Name=@"LevelFlowContent")]
public partial class LevelFlowContent : global::protoBuf.IExtensible
{
publicLevelFlowContent() {}
privateglobal::protoBuf.IExtensionextensionObject;
global::protoBuf.IExtensionglobal::protoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
{ returnglobal::protoBuf.Extensible.GetExtensionObject(ref extension Object, createIfMissing); }
//Nesting this class will cause a crash
//Under4.6.4builds
//public partial classA
// {
// }
}
//Using this class will no longer cause a crash
//Under4.6.4builds
public partial class A
{
}
}
}
Encoding and decoding in main looks like this:
public class main : MonoBehaviour {
voidStart () {
TestLevelFlowContentSerialize();
Debug.Log ("Finished!");
}
void TestLevelFlowContentSerialize()
{
Debug.Log ("Begin TestLevelFlowContentSerialize...");
LevelFlowContent lfc = new LevelFlowContent();
var bytes = EncodeContent(lfc);
Debug.Log ("bytes.length: " + bytes.Length);
lfc = DecodeContent<LevelFlowContent>(bytes);
Debug.Log ("End TestLevelFlowContentSerialize...");
}
byte[] EncodeContent(object content)
{
MemoryStream ms = newMemoryStream();
ProtoBuf.Serializer.Serialize(ms, content);
return ms.ToArray();
}
T DecodeContent<T>(byte[] buffer)
{
T content = default(T);
try
{
MemoryStream ms = new MemoryStream(buffer);
content = ProtoBuf.Serializer.Deserialize<T>(ms);
}
catch (Exception e)
{
content = default(T);
Debug.Log (string.Format("DecodeContent error: {0}", e.ToString()));
}
return content;
}
}