2014-02-22 82 views
-2

C++ DirectX11 visual studio 2012.我已將GKController1類聲明爲ref類。 我是C++編程的新手,我沒有編寫大部分代碼,所以我不明白爲什麼它會突破。如果你需要更多的代碼,只需要問。謝謝。DirectXGame.exe中0x00B84CD6未處理的異常:0xC0000005:訪問衝突讀取位置0x000000DC

在此處,它打破了代碼:

Background.cpp文件

int GameBackGround::PlayingGame() 
{ 
    if (this->controller1->IsPauseRequested()) //Breaks here, it doesn't even allow me to step into the method, it just breaks 
    { 
     //Game Paused 
     return 3; 
    } 
}` 

Background.h文件

GKController1^ controller1; 

//GKController1 file 
bool GKController1::IsPauseRequested() 
{ 
    if (gamepadConnected) 
    { 
     if (this->gamepadState.Gamepad.wButtons & XINPUT_GAMEPAD_BACK 
      && !(this->previousGamepadState.Gamepad.wButtons & XINPUT_GAMEPAD_BACK)) 
     { 
      return true; 
     } 
     else 
     { 
      return false; 
     } 
    } 
    else 
    { 
     return this->escKeyPressed; 
    } 
} 
+0

沒有看到更多的代碼我會說你可能試圖從空指針值訪問內存偏移量。在開始嘗試修復某人的代碼之前,最好先熟悉該語言的基礎知識。總之,如果'controller1'是一個指針,並且包含對象允許一個狀態,那個成員變量可以是一個空指針值,你需要在訪問它指向的內存之前檢查它。 –

回答

0
if (this->controller1->IsPauseRequested()) //Breaks here, it doesn't even allow me to step into the method, it just breaks 

controller1幾乎可以肯定是一個壞的指針。當您解除引用時(->IsPaurRequested()),您會收到訪問衝突,因爲您正在閱讀您不屬於自己的內存。

你在哪裏初始化它?我看到這個聲明,但你需要在某個地方初始化它。該成員與聲明類相同。爲什麼需要?看起來你只是通過一切,爲什麼不使用IsPauseRequested()this->IsPauseRequested())?

+0

哦,可能是無盡的實例化的恐怖;) –

+0

@CaptainObvlious:哈哈,哎呀,這是我得到的盲目複製成員類型,而不是注意。謝謝。 –

+0

忘記初始化它:)。謝謝。 – sitBy

相關問題