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.
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.
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".)
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)
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.
If you want to try your luck with std::vector, leave your animArraysstruct 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.