Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by yoyo · Dec 14, 2011 at 01:18 AM · webplayerserialization

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 


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by GeraldOBBI · Dec 14, 2011 at 07:06 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Dec 14, 2011 at 07:28 PM 0
Share

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.

avatar image mindlube · Aug 21, 2012 at 03:31 AM 0
Share

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

avatar image
7

Answer by marc.gravell · Oct 12, 2012 at 11:58 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Oct 12, 2012 at 06:10 PM 0
Share

Great, thanks $$anonymous$$arc!

avatar image
1

Answer by riffraff · Mar 19, 2012 at 08:38 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sgreenwood · May 03, 2012 at 08:07 PM 0
Share

Hi, I've gotten further using PLAT_NO_INTERLOC$$anonymous$$ED, 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 $$anonymous$$ySerializer.Write (.SerializableQuat , ProtoBuf.ProtoWriter ) [0x00000] in :0

Any ideas? Thanks in advance.

avatar image sgreenwood · May 03, 2012 at 09:38 PM 0
Share

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

avatar image
0

Answer by riffraff · Mar 19, 2012 at 08:38 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Webplayer deserialization fails 1 Answer

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

Web Player Serialization Broken 0 Answers

Sending binary data causes unexpected problems on server. 1 Answer

Help with Binary serialization/de-serialization of List items and the WEBPLAYER 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges