Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects
Please error, or at least warn, when a managed type is included in INetworkSerializeByMemcpy
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.3k
- 派生
- 461
- 平均合并
- 3 天 16 小时
- 30 天内合并 PR
- 20
描述
Is your feature request related to a problem? Please describe.
My coworker was unfamiliar with INetworkSerializeByMemcpy and the FixedStringNNNBytes types, and added a string field to an existing INetworkSerializeByMemcpy struct. This caused me great headaches (it made it into a publicly released patch), trying to track down segfault heap corruption that only showed up in very specific multiplayer circumstances (the string was normally null, which probably masked the issue).
Describe the solution you'd like
Please cause a build error when a managed type (a class, a string, or the like) is included in an INetworkSerializeByMemcpy type. I cannot think of any use case where it would be valid or intended to serialize a managed GC pointer by memcpy. At least a warning if nothing else.
It doesn't have to be perfect, even just checking for string would be lovely - string specifically is such a massive footgun, it's so easy to accidentally include and think it'll work fine. The fact it crashes later on via unrelated segfault heap corruption bringing down the editor, instead of a C# Exception, is especially rough.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先定位 INetworkSerializeByMemcpy 的定义及其验证或序列化测试。跟踪实现该接口的类型在编译期间或运行时如何受到检查,然后为 string 字段和其他托管字段添加覆盖;当此类类型产生构建错误或警告,而不是进行不安全的 memcpy 序列化时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp
- 领域
- networking
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100