C++ DirectXGame.exe中0x00B84CD6处未处理的异常:0xC0000005:访问冲突读取位置0x000000DC

C++ DirectXGame.exe中0x00B84CD6处未处理的异常:0xC0000005:访问冲突读取位置0x000000DC,c++,C++,C++DirectX11 visual studio 2012。我已将GKController1类声明为ref类。 我对C++编程很陌生,我没有编写大部分代码,所以我真的不明白为什么它会崩溃。如果您需要更多的代码,请询问。谢谢 以下是代码的中断处: Background.cpp文件 int GameBackGround::PlayingGame() { if (this->controller1->IsPauseRequested()) //Breaks here, it d

C++DirectX11 visual studio 2012。我已将GKController1类声明为ref类。 我对C++编程很陌生,我没有编写大部分代码,所以我真的不明白为什么它会崩溃。如果您需要更多的代码,请询问。谢谢

以下是代码的中断处:

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;
    }
}
控制器1几乎可以肯定是一个坏指针。当您解除对它的引用->IsPaurRequested时,您会收到访问冲突,因为您正在读取您不拥有的内存


你在哪里初始化它?我看到了声明,但您需要在某个地方初始化它。该成员与声明类的类型相同。为什么需要它?看起来您只是在传递所有内容,为什么不直接使用IsPauseRequested this->IsPauseRequested?

而不查看更多代码呢?我想说,您可能正在尝试从空指针值访问内存偏移量。在你开始修复别人的代码之前,最好先熟悉该语言的基本知识。简而言之,如果controller1是一个指针,并且包含的对象允许一种状态,其中该成员变量可以是一个空指针值,那么在访问它指向的内存之前,您需要检查它@队长:哈哈,哎呀,这就是我盲目复制成员类型而不注意的结果。谢谢。忘记初始化它了:。谢谢
if (this->controller1->IsPauseRequested()) //Breaks here, it doesn't even allow me to step into the method, it just breaks