2015-05-14 77 views
2

我有一個Unity3D移動國際象棋應用程序我使用Unity 3D 4.6.5f1從32位移植到64位。它使用OpenGLS2.0,.NET 2.0庫和通用二進制文件正在生成。Unity2D的IL2CPP編譯器運行時錯誤iOS 64位

我得到一個運行時錯誤,在調試器說以下內容:

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() 

(文件名:4294967295:目前沒有il2cpp行提供)

它使用單聲道2.0,但只要正常編譯當我將它移植到64位通用二進制文件的IL2CPP時,它會引發錯誤。

它引用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

這可能是IL2CPP中的一個錯誤,雖然我還不確定。在Xcode中,您可以嘗試調試生成的C++代碼以獲得更多信息。具體而言,你可以在il2cpp-codegen.h文件的NullCheck函數中設置一個斷點嗎?這是IL2CPP用來像這樣拋出NullReferenceException的函數。從該斷點開始,您應該能夠查找調用堆棧並查看哪部分代碼實際上具有空引用。 –

+1

也許嘗試移動到Unity 5.0.1?自從4.6 – Utamaru

+0

以來,有很多錯誤修復或IL2CPP發生。我也嘗試過該選項。我在想,我在ChessEngine.cs中使用的列表類型與IL2CPP編譯器不兼容。 – ApolloSoftware

回答

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和我的字典和列表類型。

+1

你介意在Unity爲我們提交一個bug嗎?它看起來像我們應該修復的東西。謝謝。 –

+0

絕對。立即提交bug! – ApolloSoftware

相關問題