我有一个Unity3D移动国际象棋应用程序我使用Unity 3D 4.6.5f1从32位移植到64位。它正在使用OpenGLS2.0,.NET 2.0库和Universal二进制文件生成。
我收到一个运行时错误,在调试器中说明如下:
NullReferenceException: A null value was found where an object instance was required.
at <PrivateImplementationDetails>..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国际象棋引擎(用C#编写)来获得适当的答案(下一步)。它在Mono 2.0中运行良好,但在IL2CPP失败。有什么想法吗?
答案 0 :(得分:2)
我终于找到了答案。初始化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类型。