Access Violation

This is a discussion on Access Violation within the Game Programming forums, part of the General Programming Boards category; Hi I'm pretty new to game prgramming and need a little help. My program compiles alright but when i run ...

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    Access Violation

    Hi
    I'm pretty new to game prgramming and need a little help.

    My program compiles alright but when i run it it crashes.

    When i debug it is says:

    Unhandled exception at 0x00401359 in DirectX setup.exe: 0xC0000005: Access violation reading location 0x00000000.
    I can post the code if you need it. Just let me know.

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    37
    I ve got a similar problem, but the reason mine crashes is because it tries to access something that doesn't exist, make sure your program isn't doing that.

  3. #3
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    it defidently exists... i hope

  4. #4
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    You're trying to dereference a null pointer.

  5. #5
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    This is going to sound very noobish, but i can't find my null pointer. I have a few pointers scattered around the place and when i don't set them to null or un-deference them.... Nothing happens.

    Tell me if i need to post my code.

  6. #6
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    You need to post your code. I'll guess that you're not setting it to null anywhere, but you also aren't initializing it. Something like this, maybe:
    Code:
    char *s;
    
    // this guy dies because s isn't initialized
    strcpy( s, "blahblah" );
    It could even be that you're doing something like this:
    Code:
    int i = 0;
    
    // no &, so it's using i as a pointer, and it's null
    scanf( "%d", i );

  7. #7
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    I've got a feeling it's got something to do with this snippet of code:
    Code:
    bool Display(float timeDelta)
    {
    	if(Device)
    	{
    		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
    			          0x00000000, 1.0f, 0);
    		
    		Device->Present(0, 0, 0, 0);
    	}
    	return true;
    }
    And my message loop:
    Code:
    int d3d::EnterMsgLoop( bool (*ptr_display)(float timeDelta) )
    {
    	MSG msg;
    	::ZeroMemory(&msg, sizeof(MSG));
    
    	static float lastTime = (float)timeGetTime(); 
    
    	while(msg.message != WM_QUIT)
    	{
    		if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
    		{
    			::TranslateMessage(&msg);
    			::DispatchMessage(&msg);
    		}
    		else
            {	
    			float currTime  = (float)timeGetTime();
    			float timeDelta = (currTime - lastTime)*0.001f;
    
    			ptr_display(timeDelta);
    
    			lastTime = currTime;
            }
        }
        return msg.wParam;
    }

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Check to see if ptr_display is NULL or not.

  9. #9
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    Can't you set a breakpoint and see where it bombs?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Istream::Release access violation? [C++]
    By A10 in forum Windows Programming
    Replies: 10
    Last Post: 01-13-2009, 09:56 PM
  2. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  3. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  4. Help! CListCtrl access violation
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2003, 01:40 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 01:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21