2013-10-19 36 views
0

我一直在這個相當長的一段時間。我正在使用C#進行嚴肅遊戲編程,並且正在研究本書第9章中找到的SoundManager代碼,如果您需要確切的參考資料。該代碼使用OpenAl設置了一個健全的管理器,並且我在Alut界面中遇到了問題(如果這是正確的話)。下面是我對工作的代碼:OpenAl和Alut製作聲音管理器

public void LoadSound(string soundId, string path) 
    { 
     int buffer = -1; 
     Al.alGenBuffers(1, out buffer); 

     int errorCode = Al.alGetError(); 
     System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR); 

     int format; 
     float frequency; 
     int size; 
     System.Diagnostics.Debug.Assert(File.Exists(path)); 
     IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency); 


     int errorCode2 = Alut.alutGetError(); 
     //string errorCodeString = Alut.alutGetErrorString(errorCode2); 
     //System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR); 
      //System.Diagnostics.Debug.Assert(data != IntPtr.Zero)); 
      //System.Diagnostics.Debug.Write(errorCode2); 

     Al.alBufferData(buffer, format, data, size, (int)frequency); 
     _soundIdentifier.Add(soundId, new SoundSource(buffer, path)); 
    } 

的問題是這條線就在這裏:System.Diagnostics.Debug.Assert(!數據= IntPtr.Zero));.當這一行沒有被註釋掉時,它總是失敗。我確實有它的工作,並不知道我做了什麼改變它,並停止工作。我在這裏發佈了另一篇文章:Load sound problem in OpenAL

我已經看過所有的東西了,從我能收集的信息來看,問題在於OpenAl在我的系統上的工作方式。爲此,我卸載了用於運行OpenAl並重新安裝的Tao框架。我也做了系統恢復,儘可能多的點,我回來了。我曾經考慮過對整個系統進行覈對,並且開始新鮮,但是如果可以的話,我想避免這種情況。

我也發現這個鏈接http://distro.ibiblio.org/rootlinux/rootlinux-ports/more/freealut/freealut-1.1.0/doc/alut.html#ErrorHandling,這幫助我瞭解更多關於Alut,但一直無法從它得到一個alut.dll,並且不能得到任何錯誤顯示。此代碼:

int errorCode2 = Alut.alutGetError(); 
     //string errorCodeString = Alut.alutGetErrorString(errorCode2); 
     //System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR); 
     System.Diagnostics.Debug.Write(errorCode2); 

我試圖找出確切的錯誤。如果我寫這樣的代碼:

int errorCode2 = Alut.alutGetError(); 
     //string errorCodeString = Alut.alutGetErrorString(errorCode2); 
     System.Diagnostics.Debug.Assert(errorCode2 != Alut.ALUT_ERROR_NO_ERROR); 
      System.Diagnostics.Debug.Write(errorCode2); 

可能是我使用的代碼都是錯誤的找到確切的錯誤,因爲我仍然在學習C#。

以下是我在尋找:

1)這是一個語法錯誤或與我的系統 2)如果是在我的系統錯誤的錯誤,有沒有文件,我不拆卸時我嘗試卸載OpenAL以刷新所有文件。 3)如何獲取alutGetError()代碼以便我可以實際讀取它的內容。

感謝您提前給予幫助。

+0

你不應該斷言指針檢索錯誤代碼之前是有效的?沒有必要獲取錯誤代碼,並且如果指針是有效的,就會拋出錯誤,實際上這是不正確的。 – Aybe

回答

0

我最近遇到同樣的問題,而通過該書,並能夠通過記錄錯誤輸出窗口,通知我通過console.writeline在那裏。 這樣做後,我檢查了輸出窗口,它給了我錯誤代碼519.在看完所有我看到一些論壇帖子推薦我重新安裝openAl來解決這個問題做了伎倆,我發現的所有鏈接沒有工作到下載,所以我不得不四處搜尋,但softTonic不得不爲我工作在我的Windows的一個7機http://openal.en.softonic.com/download

IntPtr的數據= Alut.alutLoadMemoryFromFile(路徑,輸出格式,大小出來,輸出頻率);

 var error= Alut.alutGetError(); 
     Console.WriteLine(error); 

     //System.Diagnostics.Debug.Assert(data != IntPtr.Zero); 

希望這有助於 helpdevelop