• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c# - Unity3D iOS 64 位的 IL2CPP 编译器运行时错误

[复制链接]
菜鸟教程小白 发表于 2022-12-12 15:17:55 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个 Unity3D 移动国际象棋应用程序,我正在使用 Unity 3D 4.6.5f1 从 32 位移植到 64 位。它使用 OpenGLS2.0、.NET 2.0 库,并且正在生成通用二进制文件。

我收到一个运行时错误,在调试器中显示如下:

 NullReferenceException: A null value was found where an object instance was required.
  at <rivateImplementationDetails>..ctor () [0x00000] in <filename unknown>:0 
  at ValilScriptObject.Update () [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.Dictionary`2+ShimEnumerator[Boo.Lang.Runtime.DynamicDispatching.DispatcherKey,Boo.Lang.Runtime.DynamicDispatching.Dispatcher].get_Current () [0x00000] in <filename unknown>:0 
System.Collections.Generic.ShimEnumerator:get_Current()

(文件名:目前在 il2cpp 线路上不可用:4294967295)

它使用 Mono 2.0 编译得很好,但是一旦我将它移植到 IL2CPP 以获取 64 位通用二进制文件,它就会抛出错误。

它引用的函数 Update() 似乎没问题。

void Update () {
    if(Request.Length>0)
    {
        string answ="";
        Answer=Engine1.GetNextMove(Request, null, Deep);
        Request="";
        if(Answer.Length>0) answ=Answer.Substring(0,2)+"-"+Answer.Substring(2,2);
        if(Answer.Length>4) answ+="="+(Answer.Substring(4,1)).ToUpper();
        ((TextMesh)GetComponent(typeof(TextMesh))).text=answ;

        //Application.ExternalCall("JSAnswer", answ);

        (GameObject.Find("Script2")).SendMessage("EngineAnswer",answ);
    }

}

它只是使用 Valil Chess Engine(用 C# 编写)来获得适当的答案(下一步)。它在 Mono 2.0 中运行良好,但在 IL2CPP 中失败。有什么想法吗?



Best Answer-推荐答案


我终于找到了答案。初始化 ChessEngine 时,会初始化一个 ChessEngine.OpeningBook 类。我干脆把这门课全部拿出来,它就像一个魅力。该类看起来像:

using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection;
//using Valil.Chess.Engine.Properties;

namespace Valil.Chess.Engine
{
    public sealed partial class ChessEngine
    {
        // hashtable with the board hash as the key and a list of moves for this board configuration as the value
        public static Dictionary<int, List<short>> book;

        // helps choose a move when the list contains more than one
        private Random random;

        /// <summary>
        /// Initializes the opening book.
        /// </summary>
        private void InitializeOpeningBook()
        {
            // initialize the random generator
            random = new Random(unchecked((int)DateTime.Now.Ticks));

            int Settings_Default_OpeningBookSize = 2755;
            //int Settings_Default_OpeningBookByteSize = 16530;

            //Assembly assembly = Assembly.GetExecutingAssembly();
            //String[] ss = assembly.GetManifestResourceNames();

            // THERE IS NO FILE & MANIFEST ASSEMBLY IN UNITY3D FOR FREE...
            // SO, CLASS ObookMem IS AS OPENING BOOK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            Stream readstream = Assembly.GetExecutingAssembly().GetManifestResourceStream("valil_silverlightchess.book.bin");

            // the "book.bin" file is a binary file with this pattern: int,short,int,short etc.
            // a 4-byte int represent a board hash, the following 2-byte short is a move (the first byte represents the starting square, the second one the ending square)

            // read "book.bin" and put the values in the hashtable
            try
            {

                using (BinaryReader br = new BinaryReader( readstream ))

//                using (BinaryReader br = new BinaryReader(new BufferedStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("Valil.Chess.Engine.book.bin"), Settings.Default.OpeningBookByteSize)))
//                using (BinaryReader br = new BinaryReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("book.bin")))


                {
                    book = new Dictionary<int, List<short>>(Settings_Default_OpeningBookSize);

                    for (int i = 0; i < Settings_Default_OpeningBookSize; i++)
                    {
                        int hash = br.ReadInt32();
                        short move = br.ReadInt16();

                        // if the hashtable already contains this hash, add the move to the list
                        // otherwise create a new list and add the pair to the hashtable
                        if (book.ContainsKey(hash))
                        {
                            book[hash].Add(move);
                        }
                        else
                        {
                            List<short> list = new List<short>(1);
                            list.Add(move);
                            book.Add(hash, list);
                        }
                    }
                }
            }
            catch
            {
            }
        }
    }
}

我认为 IL2CPP 编译器不喜欢 System.Reflection 以及我的 Dictionary 和 List 类型。

关于c# - Unity3D iOS 64 位的 IL2CPP 编译器运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30244908/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap