x


Does protobuf-net work in the Unity web player?

We recently started using the protobuf-net implementation of Google Protocol Buffers for binary serialization of data going from our Unity client to our game server. Protobuf works great for us in the editor and in standalone builds, and this thread indicates it can be made to work on iOS too, but we are having trouble with the web player.

Before we dive deeper, has anyone been able to use protobuf-net in the Unity web player?

If we know it can work then we'll keep trying to sort it out, but anyone knows it can't work then we'd like to give up quickly!

Here's the error we're getting -- BufferPool.GetBuffer is internal to the protobuf-net library, and the method that's causing the trouble is a call to Interlocked.Exchange, which is a standard .NET threading call. Quite possibly the Unity implementation of System.Threading for the web player is incomplete. We could start massaging protobuf-net to get rid of these calls, but would prefer not to if there is a better alternative.

MethodAccessException: Attempt to access a private/protected method failed.
at System.Security.SecurityManager.ThrowException (System.Exception ex) 0x00000 in :0 
at ProtoBuf.BufferPool.GetBuffer () 0x00000 in :0 
at ProtoBuf.ProtoWriter..ctor (System.IO.Stream dest, ProtoBuf.Meta.TypeModel model, ProtoBuf.SerializationContext context) 0x00000 in :0 
more ▼

asked Dec 14 '11 at 01:18 AM

yoyo gravatar image

yoyo
6.4k 25 39 84

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

It appears that protobuf-net introduced the Interlocked.Exchange in order to create a pool of buffers. Earlier versions of proto-buf simply return a new byte[] with the required size.

We were able to get proto-buf working with our webplayer build using the .Net 2.0 version of the dll at revision proto-buf r282.

more ▼

answered Dec 14 '11 at 07:06 PM

GeraldOBBI gravatar image

GeraldOBBI
87 3 3 9

So I guess protobuf-net thoughtfully added thread-safety and broke the Unity web player in the process. We should get in touch with the developer to ensure the latest version can be made compatible with the web player.

Dec 14 '11 at 07:28 PM yoyo

protobuf-net v2 r580 has a unity .dll "specific to unity (avoids missing "interlocked" methods)". there is a new precompiler too. very cool stuff!

Aug 21 '12 at 03:31 AM mindlube
(comments are locked)
10|3000 characters needed characters left

Hi all; I'm the author of protobuf-net, and I'd like to clarify:

Firstly, there is (or maybe at some point, was) an annoying glitch where-by the Interlocked methods are (/were) not public, which is where the unavailable method exceptions came from; the download from google-code includes a "unity" build which automatically compensates for this (and doesn't use unsafe code, etc), so as long as you use the "unity" build, you should be fine.

If any other problems occur, I will do my best to investigate, but I'm not a unity expert (plus I don't have a license, so the "pro" features are out of my reach unless the unity folks donate me a license for support purposes). I do, however, hear that it generally works fine.

Edit: it was brought to my attention that the "unity" build was not including the "no unsafe code" symbol, which caused problems on web-player. This has been fixed, with r594 now available on google-code as a pre-built binary that is confirmed working.

more ▼

answered Oct 12 '12 at 11:58 AM

marc.gravell gravatar image

marc.gravell
46 2

Great, thanks Marc!

Oct 12 '12 at 06:10 PM yoyo
(comments are locked)
10|3000 characters needed characters left

Simplest solution is to compile recent version of protobuf-net with flag PLAT_NO_INTERLOCKED. I tested it under Unity 3.5 + WebPlayer and it is working fine.

more ▼

answered Mar 19 '12 at 08:38 PM

riffraff gravatar image

riffraff
30

Hi, I've gotten further using PLAT_NO_INTERLOCKED, but I'm still getting exceptions from using floats on webplayer builds.

VerificationException: Error verifying ProtoBuf.ProtoWriter:WriteSingle (single,ProtoBuf.ProtoWriter): Invalid type (Float64) at stack for conversion operation. Numeric type expected at 0x0011 at MySerializer.Write (.SerializableQuat , ProtoBuf.ProtoWriter ) [0x00000] in :0

Any ideas? Thanks in advance.

May 03 '12 at 08:07 PM sgreenwood

I got it working when I also set it to FEAT_SAFE. ( Along the way, I had set the project to NET 2.0 only and removed binary formatter and xml defines )

May 03 '12 at 09:38 PM sgreenwood
(comments are locked)
10|3000 characters needed characters left

I can not made revision 282 to work with Unity3.5, so I took the most recent version of proto-buffers from svn, and compiled it with flag PLAT_NO_INTERLOCKED. It is working fine with Unity3.5 and WebPlayer.

more ▼

answered Mar 19 '12 at 08:38 PM

riffraff gravatar image

riffraff
30

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x810
x178
x2

asked: Dec 14 '11 at 01:18 AM

Seen: 2354 times

Last Updated: Oct 12 '12 at 06:10 PM