Variables sorting
Maybe this isn't the most appropriate forum to discuss about this, but I'll try... Sorry if it isn't
I found a really strange error while developing my game (using C++): if I sort the variables inside a class in a certain way, it works, but if the variables are sorted in another way the game crashes when I declare the first instance of that class.
I've been googling for this kind of problem for a lot of time, but I didn't find anything about it...
Does anyone know this problem (and possibly its solution)?
We'll have to see specific code. Can you post examples to pastebin?
I may be able to help is you post examples of the code that works versus the code that breaks. I don't think code will format very well on OGA, so a pastebin link would probably be best.
Bart
Here's the code: http://pastebin.com/AVewdThx
I included the features that needed the variable unitStatus (the last one in the non-working version) lately, so I simply declared the variable at the bottom of the list.
I found out that not only unitStatus cause the crash, but also any other variable (e.g. bool a)...
The only difference I see between the two is where unitStatus is declared...?
The only thing that comes to mind: this line
int x, y;
Maybe break that into two lines. It shouldn't matter in c++ but I guess that could be compiler-dependent:
int x;
int y;
Splitting the two variables didn't solve the error... and yes, the only difference is the position of unitStatus
One other thing is to check default values for all of these variables (maybe all your initializations in your constructor). Anything not explicitly set will be a garbage value. Moving unitStatus might be changing your memory in a deterministic (for now) way and causing this weirdness.
Similarly, double-check that you're not stepping out of your array bounds.
Problem solved! You were right, the variable curAnim wasn't esplicitly set...
Thank you for your help :)
Excellent! Looks like all that time I spend chasing my own bugs is paying off.
I'm too late, but a hint for the future: in my experience, about 80-90% of "weird" bugs in C++ are uninit. variables, even when it totally doesn't look like it.