What is wrong with my HandleEvents function?

Hello, what this function is suppose to do is wait for the user to either click button one, button two, or ex out the program. Instead, i get this error:
1
2
Unhandled exception at 0x00973faa in TicTacToe v2.0.exe: 0xC0000005: 
Access violation reading location 0xfeeefeee.


Here is the code that triggers this error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

void Title::HandleEvents( SDL_Event event )
{
	//While there's events to handle
	while( SDL_PollEvent( &event ) )
	{
		if( event.type == SDL_MOUSEBUTTONDOWN )
		{
			if( event.button.button == SDL_BUTTON_LEFT )
			{
				int x = event.button.x;
				int y = event.button.y;

				if( (x > 200 && x < 300) && (y > 160 && y < 200 ) )
				{
					SetNextState( STATE_TITLE, STATE_1PLAYER );
				}
				if( (x > 330 && x < 430) && (y > 160 && y < 200 ) )
				{
					SetNextState( STATE_TITLE, STATE_2PLAYER );
				}
			}
		}
		if( event.type == SDL_QUIT )
		{
			//Quit the program
			SetNextState( STATE_TITLE, STATE_EXIT );
		}
	}
}
I don't see anything wrong with that code. What exact line does the crash happen on?

On a side note, it seems very strange that you would pass an SDL_Event event to this function. I would get rid of that and just make SDL_Event local to the function instead of a parameter.
Thanks for the reply!

EDIT: i just noticed that in the output it says:
 
The program '[3492] TicTacToe v2.0.exe: Native' has exited with code -1073741819 (0xc0000005).


But cant tell what the exact line is. If i try doing that thing with the red circle on the side ( sorry i cant remember what its called... break point maybe?) the arrow just keeps going to the top of the while loop and then to the bottom... then to the top and to the bottom. Oh and i fixed what you said about passing an event to the function but im still getting the same problem.

Here is my main function if it helps:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int main(int argc, char* argv[])
{
	//The frame rate regulator
	Timer fps;

	if( Init() == false )
		return 1;

	stateID		 = STATE_INTRO;
	currentState = new Intro();

	while( stateID != STATE_EXIT )
	{
		//Start the frame timer
		fps.Start();

		currentState->HandleEvents();
		currentState->Logic();
		currentState->Render( screen );

		//IF needed, change the state
		ChangeState( currentState, currentState->nextState );


		//Update the screen
		if( SDL_Flip( screen ) == -1 )
			return 1;

		//Cap the frame rate
		if( fps.GetTicks() < 1000 / FRAMES_PER_SECOND )
			SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.GetTicks() );

	}
	return 0;
}
Last edited on
Yes those are called breakpoints.

I don't see any problems here, either.

I would suspect the problem is with ChangeState since that seems to be doing pointer work, and you have a bug that's typically caused by screwing up pointer work.

If you could upload the whole source somewhere so I could see all of it, that would be even better.
@ disch:

Here is the code for ChangeState:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void ChangeState( GameState *currentState, int nextState )
{
	//If the state needs to be changed
	if( nextState != STATE_NULL )
	{
		//Delete the current state
		if( nextState != STATE_EXIT )
		{
			delete currentState;
		}

		//Change the state
		switch( nextState )
		{
		 case STATE_TITLE:
			currentState = new Title();
			break;
		  case STATE_2PLAYER:
			currentState = new MultiPlayer();
			break; 
		}
	}
}


Here is the whole folder that contains all the files i use( about 7MB ):
http://www.mediafire.com/?ci8mz64ou7hop68

You're going to need SDL.h, SDL_image.h, and SDL_ttf.h to compile it.
Last edited on
Topic archived. No new replies allowed.