在 DirectXGame.exe 中0x00B84CD6出现未经处理的异常:0xC0000005:访问冲突读取位置0x

Unhandled exception at 0x00B84CD6 in DirectXGame.exe: 0xC0000005: Access violation reading location 0x000000DC

本文关键字:异常 0xC0000005 访问冲突 0x 位置 读取 处理 exe DirectXGame 0x00B84CD6      更新时间:2023-10-16

>C++ DirectX11 Visual Studio 2012.我已经宣布我的GKController1类为参考类。我是C++编程的新手,我没有编写大部分代码,所以我真的不明白为什么它会中断。如果你还需要代码,就问吧。谢谢。

下面是它中断的代码:

背景.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;
    }
}`

背景.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;
    }
}
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())?

相关文章: