我有一个 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-推荐答案 strong>
我终于找到了答案。初始化 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/
|