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

-2

C++ DirectX11 visual studio 2012. I have declared my GKController1 class as a ref class. I am new to C++ programming and I didn't write most of this code so I don't really understand why it's breaking. If you need anymore code just ask. Thanks.

Here's the code where it breaks:

Background.cpp file

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 file

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;
    }
}
c++
asked on Stack Overflow Feb 22, 2014 by sitBy • edited Feb 22, 2014 by Captain Obvlious

1 Answer

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

controller1 is almost certainly a bad pointer. When you dereference it (->IsPaurRequested()) you receive an access violation because you are reading memory you don't own.

Where are you initializing it? I see the declaration, but you need to initialize it somewhere. The member is of the same type as the declaring class. Why is it needed? It looks like you're just passing everything through, why not just use IsPauseRequested() (this->IsPauseRequested())?

answered on Stack Overflow Feb 22, 2014 by Ed S. • edited Feb 23, 2014 by Ed S.

User contributions licensed under CC BY-SA 3.0