CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2011
    Posts
    29

    unhandled exception?

    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:
    Code:
    Unhandled exception at 0x00973faa in TicTacToe v2.0.exe: 0xC0000005: 
    Access violation reading location 0xfeeefeee.
    Here is the code that triggers this error:
    Code:
    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 );
    		}
    	}
    }

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: unhandled exception?

    Have you run it in the debugger to see what line of your code is causing this?

    Viggy

  3. #3
    Join Date
    Jun 2011
    Posts
    29

    Re: unhandled exception?

    @viggy:

    The problem is inside of a while loop that waits for an event, so when i debug look like i cant see what the exact line of code.

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: unhandled exception?

    You should have a stack trace that shows what call inside your code ultimately leads to the exception. Then, you look to see that all your variables are what you expect them to be.

    Viggy

  5. #5
    Join Date
    Jun 2011
    Posts
    29

    Re: unhandled exception?

    @viggy: not really sure how to do that but here is the project so you can take a look at it.

    http://www.mediafire.com/?722s9rsjneo51bw

  6. #6
    Join Date
    Jul 2011
    Posts
    3

    Re: unhandled exception?

    In visual studio 2005 (and probably later ones too) there is a little icon that looks like a window with three little windows on top of it. Hovering your mouse over it shows the label "Call Stack". Clicking this at a breakpoint or error will bring up a window at the bottom that shows the whole history of the program up until that point. You can double-click each line to take you to the section of code, and hovering your mouse over any variable should tell you what it equals.
    Do this, and you will find the source of your problem.

  7. #7
    Join Date
    Jun 2011
    Posts
    29

    Re: unhandled exception?

    @ quantumcat:

    I clicked what you said but all that happend was a box came up with a graph of weird letters and stuff. If i doubled click a line it just brought up some weird .cpp's.

  8. #8
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: unhandled exception?

    Have you tried setting a break point on the first line in SetNextState and single step from that point?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured