Goodday所有, 我收到以下錯誤:如何解決在C++中「訪問違反讀取位置錯誤」?
First-chance exception at 0x67887AB7 (SDL2_mixer.dll) in Racing.exe: 0xC0000005: Access violation reading location 0xCCCCCCD4.
我想問題可能是與指針,但我沒有經歷過足夠++在C語言中找到它。 我希望有人可以告訴我我做錯了什麼,並希望我可以從中學習:)
試圖從我的gamebus調用它。
Music Mus;
Mus.SpeelGeluid("crash");
音樂類
bool Music::LoadMusic(){
//Load music
Mix_Music *gMusic = NULL;
gMusic = Mix_LoadMUS("MusicTest.wav");
Mix_PlayMusic(gMusic, -1);
bool success = true;
if (gMusic == NULL)
{
printf("Failed to load Music background song! SDL_mixer Error: %s\n", Mix_GetError());
success = false;
}
// Load sound effects
Mix_Chunk *gCrash = NULL;
gCrash = Mix_LoadWAV("Crash.wav");
if (gCrash == NULL)
{
printf("Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError());
success = false;
}
return success;
}
void Music::SpeelGeluid(string soundname){
cout << soundname << endl;
if (soundname == "crash")
{
try
{
Mix_PlayChannel(-1, gCrash, 0);
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << '\n';
}
}
else
{
} }
謝謝您的時間
是的,這可能是一個指針。但是,我們無法調試您的代碼。您需要在調試器中逐步完成它,或者使用打印語句來縮小問題的範圍。 – user3344003 2014-10-07 19:46:10
您需要在'Mix_PlayMusic(gMusic,-1);'之前檢查'gMusic'是否爲'NULL'。 – molbdnilo 2014-10-07 19:48:31