开发者

Receiving EXC_BAD_ACCESS with SDL_Event* in C++

I've read many(MANY!) EXC_BAD_ACCESS examples but non of the solutions provided seems to be working for the issue I have. Basically, I have a gameloop that looks like this:

int GameEngine::Run()
{

    if( this->OnInit() == false )
        return -1;

 开发者_StackOverflow   SDL_Event Event;

    while( this->IsRunning )
    {

        while( SDL_PollEvent( &Event ) )
        {

            INPUT->Event( &Event );
            for( int i = 0; i < this->objects.size(); i++ )
            {

                this->objects[i]->OnEvent();

            }

            if( INPUT->Type( SDL_QUIT ) )
               this->Stop();

        }

        this->OnLoop();
        this->OnRender();

    }

    this->OnCleanUp();

    this->PrintObjects();

    return 0;

}

It is most likely the

INPUT->Event( &Event );

that is causing the trouble. This function looks like this in the Input class:

void Input::Event( SDL_Event* CurrEvent ) { this->Current_Event = CurrEvent; }

(This is also the line that gives me the EXC_BAD_ACCESS)

So this->Current_Event in Input class will always contain the current event since it will be updated from the game loop with the event that was the latest to be polled.

Currently I don't know how to get the stacktrace in Xcode but if I do some manual trace it goes like the following:

Input::Event()
GameEngine::Run()
main()

And then it goes into SDL code.

Does anyone know what might be the problem here? Tell me if you need to know anything else!


EXC_BAD_ACCESS is saying is that you did something that caused a pointer (yours, one internal to your device, or one that the allocator is using) to be dereferenced and that memory location isn’t inside one of the chunks assigned to your program.

with SDL_Event* here, it is raised because INPUT is not initialized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜