我一直在這個相當長的一段時間。我正在使用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()代碼以便我可以實際讀取它的內容。
感謝您提前給予幫助。
你不應該斷言指針檢索錯誤代碼之前是有效的?沒有必要獲取錯誤代碼,並且如果指針是有效的,就會拋出錯誤,實際上這是不正確的。 – Aybe