BananaHemic / Mumble-Unity

Performant Mumble Client For Unity3D
MIT License
82 stars 30 forks source link

protobuf error on iOS #50

Open bodybreaker opened 2 years ago

bodybreaker commented 2 years ago

Thank you for your great job!

Im using Mumble-Unity on iOS, Android. Android works great but iOS I had to build opus codec . After that I got this error, I think it has problem with Protobuf.(on google, people say it's related with protobuf code generation) I'm new at protobuf so any help would be grateful I attached my error log

NotSupportedException: System.Reflection.Emit.DynamicMethod::.ctor
  at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, System.Boolean skipVisibility) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Compiler.CompilerContext..ctor (System.Type associatedType, System.Boolean isWriter, System.Boolean isStatic, ProtoBuf.Meta.TypeModel model, System.Type inputType) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Compiler.CompilerContext.BuildSerializer (ProtoBuf.Serializers.IProtoSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Serializers.CompiledSerializer..ctor (ProtoBuf.Serializers.IProtoTypeSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Serializers.CompiledSerializer.Wrap (ProtoBuf.Serializers.IProtoTypeSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.MetaType.CompileInPlace () [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.MetaType.get_Serializer () [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.RuntimeTypeModel.Serialize (System.Int32 key, System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.TypeModel.SerializeCore (ProtoBuf.ProtoWriter writer, System.Object value) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object value, ProtoBuf.SerializationContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object value) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Serializer+NonGeneric.Serialize (System.IO.Stream dest, System.Object instance) [0x00000] in <00000000000000000000000000000000>:0 
  at Mumble.MumbleTcpConnection.SendMessage[T] (Mumble.MessageType mt, T message) [0x00000] in <00000000000000000000000000000000>:0 
  at Mumble.MumbleTcpConnection.SendVersion () [0x00000] in <00000000000000000000000000000000>:0 
  at Mumble.MumbleTcpConnection.OnTcpConnected (System.IAsyncResult connectionResult) [0x00000] in <00000000000000000000000000000000>:0 
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.SocketAsyncResult+<>c.<Complete>b__27_0 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.WaitCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as InvalidOperationException: It was not possible to prepare a serializer for: MumbleProto.Version
  at ProtoBuf.Compiler.CompilerContext.BuildSerializer (ProtoBuf.Serializers.IProtoSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Serializers.CompiledSerializer..ctor (ProtoBuf.Serializers.IProtoTypeSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Serializers.CompiledSerializer.Wrap (ProtoBuf.Serializers.IProtoTypeSerializer head, ProtoBuf.Meta.TypeModel model) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.MetaType.CompileInPlace () [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.MetaType.get_Serializer () [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.RuntimeTypeModel.Serialize (System.Int32 key, System.Object value, ProtoBuf.ProtoWriter dest) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.TypeModel.SerializeCore (ProtoBuf.ProtoWriter writer, System.Object value) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object value, ProtoBuf.SerializationContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Meta.TypeModel.Serialize (System.IO.Stream dest, System.Object value) [0x00000] in <00000000000000000000000000000000>:0 
  at ProtoBuf.Serializer+NonGeneric.Serialize (System.IO.Stream dest, System.Object instance) [0x00000] in <00000000000000000000000000000000>:0 
  at Mumble.MumbleTcpConnection.SendMessage[T] (Mumble.MessageType mt, T message) [0x00000] in <00000000000000000000000000000000>:0 
  at Mumble.MumbleTcpConnection.SendVersion () [0x00000] in <00000000000000000000000000000000>:0 
  at Mumble.MumbleTcpConnection.OnTcpConnected (System.IAsyncResult connectionResult) [0x00000] in <00000000000000000000000000000000>:0 
  at System.AsyncCallback.Invoke (System.IAsyncResult ar) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.SocketAsyncResult+<>c.<Complete>b__27_0 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.WaitCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <00000000000000000000000000000000>:0 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
BananaHemic commented 2 years ago

Wowzers, that is a big call stack. I think you're right that the issue is with protobuf code generation. I know that iOS doesn't allow allocated memory to be marked executable, so maybe that's why it fails to prepare a serializer for the version.

How are you building the opus codec for iOS?

bodybreaker commented 2 years ago

Thank you for your comment!

I build opus on macOS with xcode 12.4, opus 1.3 maybe I can share codec!

Do you think is there easy way to solve it?? Like disable code generation of protobuf..

Thank you again!

BananaHemic commented 2 years ago

Doing some research, it seems that the issue is that reflection isn't supported on ios, and that's what is used in your call stack. I'm certain that this is solvable, but it won't be easy. I think you're best bet is to get protobuf-unity working in a separate project on iOS, and confirm that it can properly serialize a mumbleproto.Version. It may be failing due to something in your build configuration, or because we need a new protobuf dll for iOS.

Also, adding opus for iOS has been on this project's TODO list for a long time, if you can get this working please consider making a PR and adding the compiled opus library for iOS, would be helpful for others.

bodybreaker commented 2 years ago

Thanks a lot for your help! okay I will try protobuf-unity with ios, and If i have a luck with that I will make a PR!

Hava a good day BananaHemic!

bodybreaker commented 2 years ago

Doing some research, it seems that the issue is that reflection isn't supported on ios, and that's what is used in your call stack. I'm certain that this is solvable, but it won't be easy. I think you're best bet is to get protobuf-unity working in a separate project on iOS, and confirm that it can properly serialize a mumbleproto.Version. It may be failing due to something in your build configuration, or because we need a new protobuf dll for iOS.

Also, adding opus for iOS has been on this project's TODO list for a long time, if you can get this working please consider making a PR and adding the compiled opus library for iOS, would be helpful for others.

I just make PR with ios opus codec.

51

But i have no luck with solve

system.reflection.emit

and I had to add assets/link.xml

<linker>
    <assembly fullname="Google.Protobuf" preserve="all"/>
    <assembly fullname="System.Reflection" preserve="all"/>
    <assembly fullname="System.Collections.Immutable" preserve="all"/>
    <assembly fullname="System.Memory" preserve="all"/>
    <assembly fullname="System.Buffers" preserve="all"/>
    <assembly fullname="System.Runtime.CompilerServices.Unsafe" preserve="all"/>
    <assembly fullname="System" preserve="all" />
    <assembly fullname="protobuf-net" preserve="all" />
</linker>

because of error with code strip in unity

BananaHemic commented 2 years ago

Did adding the link.xml file solve the problem?

Thanks for the PR! I'll merge it once we get your system running on iOS

bodybreaker commented 2 years ago

No adding link.xml for other error (method not found exception)

I tried protobuf-unity on mumble unity, but it has some compile error, I thought it can be changed with your protobuf-net.dll.. Im new at unity,C# I couldn't handle it 😭😭

BananaHemic commented 2 years ago

Well I'm here to help you out 😄

Can you first get protobuf-unity compiling in a brand new project? Once that's running on iOS, then we can bring in the mumble files and see what happens.