denghongcai / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Unity android crash when serializing object #318

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?
I don't know exact condition. It generally works well. Sometime android app 
crash when serializing object, even when use try-catch block.

What is the expected output? What do you see instead?
Expected output: no error.
What I see is error log in logcat below and app crash

DEBUG : singal 11 (SIGSEGV) code 1 (SEGV_MAPERR), fault addr 3bf6745c

What version of the product are you using? On what operating system?
Win7 64bit, protobuf-net r480 or r580, Unity 3.5.x, Android 2.2.2 or 2.3.6

Please provide any additional information below.

My code is below

public static byte[] Serialize(object data)
        {
            MemoryStream ms = new MemoryStream();

            try
            {
                Serializer.Serialize(ms, data);
                return ms.ToArray();
            }
            catch (Exception ex)
            {
                Debug.Log("Serialize Error: " + ex.Message);
                return null;
            }
        }

It probably related to writing to memory
App crash at Serializer.Serialize(ms, data). I can't even see exception error 
message.

Any clue or walk around?

email: high2bluesky@gmail.com

Original issue reported on code.google.com by stylix...@gmail.com on 10 Sep 2012 at 1:13

GoogleCodeExporter commented 9 years ago
The lack of an exception message makes it tricky. I do not have a unity license 
to repro (I asked, they said yes, then never delivered despite multiple 
requests). Perhaps the first thing to try is switching to a dedicated 
serializer, via "precompiler":

http://marcgravell.blogspot.co.uk/2012/07/introducing-protobuf-net-precompiler.h
tml

So:

- your DTO and app assemblies would reference one of the "core-only" builds; 
perhaps the "unity" one
- you run precompiler against your DTO dll, and it generates a serializer dll
- you reference that serializer dll from your app, and instead of 
`Serializer.Serialize(...)` you would use `new 
MyCustomSerializer().Serialize(...)`

worth a try?

Original comment by marc.gravell on 10 Sep 2012 at 7:22

GoogleCodeExporter commented 9 years ago
Thank you for reply.

In my case, precompiling is hard to be apply, because it cause circular 
references of dll.

So I have tried to import directly protobuf-net core source code into Unity 
project.

Unity shows error messages "Unsafe code requires the `unsafe' command line 
option to be specified" in ProtoReader.cs and ProtoWriter.cs

I guess that unsafe block is not good for Unity.
Actually, Logcat error message "singal 11" has something to do with memory 
access.

I wanna to try with totally managed code.
Is there a way to remove "unsafe" keyword?

Original comment by stylix...@gmail.com on 10 Sep 2012 at 11:56