SDL_Event gives me an EXC_BAD_ACCESS

Hey again!

I’ve been working a lot on my GameEngine and currently hit a snag.
To explain my problem I think I need to explain how the code is structured.

I have a class called GameObject which is the different objects in the game. Each GameObject can ->AddSprite( new Sprite() ) to add a texture to the game object aswell as a ->AddEvent( new CustomEventClassThing() ). These CustomEvents are meant for the user that implements the GameEngine to create and must inherit from Event.h which is a class that contains a lot of virtual On***** events function and one main OnEvent(SDL_Event* Event) which routes the event to the correct function depending on what type of event. In Event.cpp all of these virtual functions are empty and that’s where the CustomEvents come in to play.

After you’ve made the GameObjects and added their properties, you add all of the game objects to the GameEngine which has a map with all of the objects in the game. Pretty easy to understand, hopefully you’re all with me so far.

The GameEngine has a function Run() which has a Initialize(), GameLoop { Events(), OnLoop(), OnRender() } and finally a OnCleanUp().
It’s the Events part that I’m struggling with.

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


So you see, I’m looping through all of the objects and call their RunEvents(). That function looks like this:


void GameObject::RunEvents( SDL_Event* Event )

for( int i = 0; i < this->events.size(); i++ )
	this->events[i]->Run( Event );


this->events is a map with all the events-inherited custom-events that has been added to that specific object.



GameObject* spacecraft = new GameObject();
spacecraft->AddEvent( new SpaceCraftKeyInput() );

this->events would then contain the SpaceCraftKeyInput which inherits from Event.
The Event::Run( SDL_Event* Event ) simply routes the SDL_Event to Event::OnEvent( SDL_Event* Event ).

It is this line that gives me the EXC_BAD_ACCESS:

this->events[i]->Run( Event );

in GameObject::RunEvents

Any idea as to why this is happening??

Hopefully I’ve explained it good enough :)[/code]