Sign in to follow this  
Svenjamin

Error writing location...

Recommended Posts

Svenjamin    153
Hey, so in a game I am making, I have four objects that need to be reset every time a new game is started. so I initialized them in a constructor, and I deleted them when the game ends. This works when I initialize them and delete them in the main init and shutdown functions of my whole game, but when I put the init and shutdown in the init and shutdown sections of the actual game state, it throws an exception something like this: Unhandled exception 0xC0000005, Error writing location 0x00000560 something like that, you have probably seen them before. does anyone know why it is doing this? Let me know if you have any questions, I think I covered everything, Thanks in advance, Svenjamin

Share this post


Link to post
Share on other sites
ApochPiQ    23064
This is a classic sign of a null pointer. Run your program in your debugger, and it should reveal what pointer is null and what code is trying to access it. From there, the fix should hopefully be pretty self-evident.

Share this post


Link to post
Share on other sites
Svenjamin    153
Hey,
I need help again, I should have mentioned that the error was occurring when I tried to initialize the member data.
Ex:

m_Cursor->m_X = 32; /* Caused the error */

then, if I set the pointer to null before I initialize it, the error occurred on that line, (setting m_Cursor = NULL)
it still gives me an error writing a location.

this might have something to do with it:
a while ago I was working on my game engine, and when I tested it once, it compiled fine, but when I ran it, it threw another exception, (I think it was an exception) but anyways, the dialog box had a line that said

DAMAGE: <some sector here>

or something like that. is it giving me an error because that space that it is trying to write to was damaged? if so, is there a way to fix it?
Thanks again,
Svenjamin.

Share this post


Link to post
Share on other sites
Endar    668
The error is happening because m_Cursor is set to NULL. Look through your code and make sure that you are assigning m_Cursor the right address either by "m_Cursor = &cursorObject;" or by using new.

That's really all the advice that we can give. Step through your debugger to the point where the m_Cursor is supposed to be set to the address and make sure it happens.

Share this post


Link to post
Share on other sites
Archi    124
Quote:
Original post by Svenjamin
Hey,
I need help again, I should have mentioned that the error was occurring when I tried to initialize the member data.
Ex:

m_Cursor->m_X = 32; /* Caused the error */

then, if I set the pointer to null before I initialize it, the error occurred on that line, (setting m_Cursor = NULL)
it still gives me an error writing a location.


You should first allocate memory for your object, like that:
m_Cursor = new CGameCursor(); // or whatever class/structure you use

then you can actually initalize member data as you've written above.

NOTE: You have to free allocated memory later like that:
delete m_Cursor;


Quote:
this might have something to do with it:
a while ago I was working on my game engine, and when I tested it once, it compiled fine, but when I ran it, it threw another exception, (I think it was an exception) but anyways, the dialog box had a line that said

DAMAGE: <some sector here>

or something like that. is it giving me an error because that space that it is trying to write to was damaged? if so, is there a way to fix it?
Thanks again,
Svenjamin.


The following code will give that exception

char array8[8]="1234567";
sprintf(array8, "TEST: %s", "OK");

array8 actually can hold 7 symbols, while I tried to write 8 ones

Share this post


Link to post
Share on other sites
Svenjamin    153
Hey,
thanks for the replies,
I should have mentioned this also, I have already allocated memory with new and I am freeing it with delete. thanks for the help, I'll keep messing around with it to see if I can get it to work.
Svenjamin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this