C# Mono aot 与 protobuf-net 获取 ExecutionEngineException

发布于 2024-10-18 14:59:06 字数 1706 浏览 7 评论 0原文

首先非常感谢 protobuf-net http://code.google.com/ 的 Marc Gravell 作者p/protobuf-net/ 。这真是一个很棒的资源。无论如何,我希望马克或其他人可以帮助我解决这个异常。

我正在尝试使用 Unity3D 游戏引擎在移动设备(iOS 和 Android)上实现 protobuf-net。 Unity 3.2 使用 Mono 2.6,这是他们对 Mono 稍作修改的版本。

它在编辑器中工作正常,但在运行时的 iOS 设备上,它在尝试序列化第一个成员时失败。请注意异常中的 --aot-only 标志。我认为 Unity 基本上是通过 Mono 的 aot 功能构建 ARM 组件,尽管我不明白它在幕后做了什么。

ExecutionEngineException: Attempting to JIT compile method 'ProtoBuf.Property.Property`2<GameManagerSaveState , bool>:.ctor ()' while running with --aot-only.

at ProtoBuf.Property.PropertyBoolean`1[GameManagerSaveState]..ctor () [0x00000] in <filename unknown>:0 
at ProtoBuf.Property.PropertyFactory.CreateProperty[GameManagerSaveState] (System.Type type, ProtoBuf.DataFormat& format, MemberSerializationOptions options) [0x00000] in <filename unknown>:0 
at ProtoBuf.Property.PropertyFactory.Create[GameManagerSaveState] (System.Reflection.MemberInfo member) [0x00000] in <filename unknown>:0 
at ProtoBuf.Serializer`1[GameManagerSaveState].Build () [0x00000] in <filename unknown>:0

IRC 上有人建议我可以提前声明这些类型的变量,这样编译器就不必在运行时对它们进行 JIT。似乎是个好主意,但不幸的是,这些就像内部泛型类型,并且不知道在 C# 中编写什么来声明变量以欺骗编译器。谁能解释一下上面的消息并让我知道编译器需要提前知道什么?还有其他策略可以防止这种情况发生吗?顺便说一句,这是错误的类中的顶部,

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf;

[ProtoContract]
public class GameManagerSaveState
{
    [ProtoMember(1)]
    public bool gameOver;
      // snip

感谢 Mono 和 protobuf 专家帮助我解决了这个问题! protobuf-net 似乎是一个很棒的轻量级序列化和 RPC 有线协议,非常适合 iOS 和 Android 应用程序,所以我期待使用它。

First a big thanks to Marc Gravell author of protobuf-net http://code.google.com/p/protobuf-net/ . It's a really great resource. Anyhow I am hoping that Marc or someone else can help me resolve this exception.

I am trying to implement protobuf-net on mobile devices (iOS and Android) using Unity3D game engine. Unity 3.2 uses Mono 2.6, their slightly modified version of mono.

It works fine in the Editor, but on the iOS device at runtime it fails at the first member it tries to serialize. Note the --aot-only flag in the exception. I think Unity basically builds ARM assembly through Mono's aot feature though I don't understand what it's doing under the hood.

ExecutionEngineException: Attempting to JIT compile method 'ProtoBuf.Property.Property`2<GameManagerSaveState , bool>:.ctor ()' while running with --aot-only.

at ProtoBuf.Property.PropertyBoolean`1[GameManagerSaveState]..ctor () [0x00000] in <filename unknown>:0 
at ProtoBuf.Property.PropertyFactory.CreateProperty[GameManagerSaveState] (System.Type type, ProtoBuf.DataFormat& format, MemberSerializationOptions options) [0x00000] in <filename unknown>:0 
at ProtoBuf.Property.PropertyFactory.Create[GameManagerSaveState] (System.Reflection.MemberInfo member) [0x00000] in <filename unknown>:0 
at ProtoBuf.Serializer`1[GameManagerSaveState].Build () [0x00000] in <filename unknown>:0

It was suggested on IRC that I could declare variables of these types ahead of time, that the compiler would not have to JIT them at runtime. Seems like a great idea, but unfortunately these are like internal generic types, and don't know what to write in C# to declare variables in order to fake out the compiler. Can anyone interpret the above message and let me know what the compiler needs to know in advance? Any other strategies for preventing this from happening? BTW Here is the top of the class where it's erroring

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using ProtoBuf;

[ProtoContract]
public class GameManagerSaveState
{
    [ProtoMember(1)]
    public bool gameOver;
      // snip

Thanks Mono and protobuf experts for helping me nail this one! protobuf-net seems to be an awesome and lightweight serialization and RPC wire protocol that would be perfect for iOS and Android apps, so I am looking forward to using it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩世 2024-10-25 14:59:06

v1 中有许多问题使得预 JIT 有点痛苦; v2 虽然不完整,但旨在解决许多/所有这些问题,尤其是通过提供预编译为 dll 选项 - 但即使是仅运行时版本也应该更加对设备更友好。

我还应该提到 Jon 的 Java 版本移植在这里应该可以很好地工作,因为它是编译器重的而不是运行时重的。

There are a number of issues in v1 that make it a bit of a pain to pre-JIT; v2, although incomplete, is intended to resolve many/all of these issues, not least by offering a pre-compile to dll option - but even the runtime-only version should be much more device friendly.

I should also mention that Jon's port of the Java version should work well here, since it is compiler-heavy rather than runtime-heavy.

末が日狂欢 2024-10-25 14:59:06

在使用 protobuf 之前使用它:

Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");

信用:
https://github.com/antonholmquist/easy-serializer-unity

Use this before using protobuf:

Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");

Credit:
https://github.com/antonholmquist/easy-serializer-unity

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文