How do I know what code an address points to?? Debugger isn't very helpful

My program keeps crashing on some function, and so I ran the debugger and it gave me an address. But, I don't know where the address belongs in the actual coding, and so I can't fix anything.

Is there any way to know?
Did you compile with debug flags?
I simply ran it in debugger, it just gives me addresses.

"Unhandled exception at 0x52cfcb17 (msvcr100d.dll) in A Winter Dream.exe: 0xC0000005: Access violation reading location 0x00b20000."

Such things. I don't know what to make of it. Using Windows Visual Studio 2010
First, make sure you're compiling with the Debug configuration (not Release).
You can change this with the drop-down menu next to the green play button thing at the top, or you can go to the Project Properties and change it at the top left.
Next, compile and then run your program by hitting F5 or pressing "Start debugging".
When your program crashes, hit "Break" and look at what line it's crashing on.
Then see if you can figure out why it's crashing there.

If you need help, post the relevant lines of code and we'll take a look at it.
Yes that is what I am doing but when I break, it only gives me the address, not the line.

Gives me

Unhandled exception at 0x77942a02 in A Winter Dream.exe: 0xC00000FD: Stack overflow.


And

Unhandled exception at 0x5284cb17 (msvcr100d.dll) in A Winter Dream.exe: 0xC0000005: Access violation reading location 0x00e70000.


I would post the code here but it is too long. More than 20k lines. It crashes when a certain function is called. The worst part is that it was working fine the night before. I did have a problem that night, however. I tried to set an object array to an array I sent by function, it crashed then. So, I removed what I had changed, and it worked fine. But, the following day it was wrecked again. Now it always crashes.
Last edited on
Set a breakpoint at the beginning of the function that crashes (right-click the line to find the menu for it) and then try to debug it.
When the program stops at that breakpoint, you can use F10 to run the next statements one at a time.
(You can also use the buttons at the top for "Step Into/Step Over/Step Out".)
Well, I don't understand.

It is at this line:

1
2
animArrays playerAnim;
	system("CLS");


Where it says

Unhandled exception at 0x77942a02 in A Winter Dream.exe: 0xC00000FD: Stack overflow.


All that struct is, is the following:

1
2
3
4
5
6
7
struct animArrays
{
	static const int BATTLE_SIZE_X=14;
	static const int BATTLE_SIZE_Y=74;

	char animations[BATTLE_SIZE_X][BATTLE_SIZE_Y];
};


It is declared at the start of the program.
Last edited on
Actually seems to be here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
for(int i=0;i<MAX_PLAYER_NUM;i++)
	{
		bool swapped=false;
		for(int j=0;j<MAX_PLAYER_NUM-1;j++)
		{
			if(fighters[j].getTotalPlayerSpeed()<fighters[j+1].getTotalPlayerSpeed())
			{
				swap(fighters[j],fighters[j+1]);

				swapped=true;
			}
		}
		if(!swapped)
			break;
	}


fighters[] is from a class I have, that class has private pointer variables. Could this be the source of the issue?
What's the value of MAX_PLAYER_NUM?

A stack overflow means you're putting too much stuff on your stack.
In this case, your animations array is declared on the stack, as well as any other arrays you might have declared with typeName myArray[SOME_SIZE];.

How many of those animArrays are you declaring?
If you have an array of a whole bunch of those things, then that could be causing that error.

For instance, this code crashes for me:
1
2
3
4
5
6
7
8
9
10
struct stuff
{
    char arr[14][74];
};

int main()
{
    stuff arrayOfStuff[1024]; // This puts > 1 MB of data on the stack --
                              // which is an overflow under default settings for me
}


If you have anything like that, I would consider switching over to std::vector instead of making a huge array like that.
(std::vector stores its elements on the heap, not the stack)
The value of MAX_PLAYER_NUM is 6.

As to the question of how many arrays I have...of that...well, I have one that is like this:

animArrays skillAnims[52][SKILL_ANIM_NUM];

SKILL_ANIM_NUM being 10, so basically

animArrays skillAnims[52][10];

But this wasn't giving me a problem before...why now?
Hmm, that array by itself shouldn't be big enough to overflow your stack.
Are there any other big objects/arrays (in other functions that call that particular function, perhaps) you might have lying around?
You may be onto something. Well, how would I switch such a thing to a vector?

You see, I am using those character arrays to store pictures (simple things made by asterisks on a text file, just doing some cheap animations really).

Would it have to be some big conversion or is there a quick way to change it to vector?
Well, I sent an array of 96 vector objects, and I have some map files that also read in stuff from text files, but only 17 of those. Each player (6 in total) has one of each animArray, so that adds an extra 6. Pretty hard to tell every single thing there.
I'd be very grateful if anyone could take a look at my program, though it is 20k lines long. A PM if anyone has the time.
If you want to try your luck with std::vector, leave your animArrays struct as it is and try changing a couple of your other big arrays from e.g.
animArrays skillAnims[52][SKILL_ANIM_NUM];
to
vector<vector<animArrays>> skillAnims(52, vector<animArrays>(SKILL_ANIM_NUM));.

(Of course, you'll need to #include <vector> .)

For a 1D array (if you have any of those that are big enough to worry you), it would be something like
1
2
3
4
// change
typeName myArray[SIZE];
// to
vector<typeName> myArray(SIZE);


Note that when using a vector of vectors, the memory might not all be contiguous, but if your program doesn't care too much about where the memory is located (i.e. you don't do any pointer arithmetic with your arrays), that should work as a "quick fix".

The normal array syntax (using [][] to access elements) should still be the same, so you won't have to change any of that.
Double main, would you be willing to have a look at my program? I mean, not to mandatorily fix it, but maybe just have a look at it, to see if there is an quick solution. Better yet, should I post this on Jobs? I need to finish this program soon.
Last edited on
Sure, I'll look at it. (Why not? :) )
Topic archived. No new replies allowed.