我们正在构建基于Unity的游戏,并且在Windows上遇到了DeflateStream的问题。 (我们正在尝试压缩通过websocket发送的包)
似乎Unity在某些平台上不支持zip:
System.DllNotFoundException: MonoPosixHelper
at (wrapper managed-to-native) System.IO.Compression.DeflateStream:CreateZStream (System.IO.Compression.CompressionMode,bool,System.IO.Compression.DeflateStream/UnmanagedReadOrWrite,intptr)
at System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen, Boolean gzip) [0x00000] in <filename unknown>:0
at System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Compression.DeflateStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode,bool)
at WebSocketSharp.Ext.compress (System.IO.Stream stream) [0x00000] in <filename unknown>:0
at WebSocketSharp.Ext.Compress (System.IO.Stream stream, CompressionMethod method) [0x00000] in <filename unknown>:0
at WebSocketSharp.WebSocket.send (Opcode opcode, System.IO.Stream stream) [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
ServerConnection:<connectToServer>m__7(Object, ErrorEventArgs) (at Assets/Scripts/Network/ServerConnection.cs:83)
WebSocketSharp.Ext:Emit(EventHandler`1, Object, ErrorEventArgs)
WebSocketSharp.WebSocket:error(String, Exception)
WebSocketSharp.WebSocket:send(Opcode, Stream)
WebSocketSharp.WebSocket:Send(String)
ServerConnection:sendRegInfo() (at Assets/Scripts/Network/ServerConnection.cs:108)
ServerConnection:onOpen() (at Assets/Scripts/Network/ServerConnection.cs:58)
ServerConnection:<connectToServer>m__4(Object, EventArgs) (at Assets/Scripts/Network/ServerConnection.cs:77)
WebSocketSharp.Ext:Emit(EventHandler, Object, EventArgs)
WebSocketSharp.WebSocket:open()
我们还发现了一些有关此错误的信息:
Mono implements System.IO.Compression.GZipStream not with a managed implementation, but it relies on a system installed zlib instead
问题是 - 有简单的变体吗?也许我们可以在我们的项目中提供zlib或其他简单的东西?我们了解SharpZipLib,但它有点奇怪的API。
答案 0 :(得分:0)
我不能说Unity的最新版本,但我有以前(3.x,4.x)压缩的经验,我认为情况没有太大变化。
Unity建立在顶级旧版本mono(v2.6)上,其中包含来自Unity团队的一些黑客,并且在整个Unity生命周期内从未升级到最新版本的mono。这意味着Unity继承了所有旧的单声道错误,这些错误已在最新版本的mono中修复。其中一个错误就是deflate stream Mono & DeflateStream的错误。 它已经在单声道中快速修复,但尚未在Unity中修复。
要解决我的Unity Web应用程序的这个错误,我必须使用Deflate流的托管实现。我决定使用Ionic.Zlib,它具有与System.IO.Compression相同的接口。
它的性能大约是本机单声道实现的3倍,但是在源中添加ifdef至少解决了服务器代码的性能问题。
#if UNITY
using Ionic.Zlib;
#else
using System.IO.Compression;
#endif