Function parameters inadvertantly changing
I'm passing an integer into a function by value. Going into the function, it's -1. However, after the first for loop within the function evaulates to false (the parameter is never touched within this loop), the integer magically changes into 1.2 million-something-or-other. I haven't touched the variable at all. If I make a copy of the number at the start of the function, both variables get screwed up. This is a bit of a burden, because I need that -1 later on in the function.
What's going on here?
Can you post code? Sounds like there's possibly an '=' (assignment operator) rather than '==' (equivelance operator) somewhere, maybe.
make sure that your variable is signed, not unsigned.
loading -1 into a unsigned variable will give you a big number
just a though
loading -1 into a unsigned variable will give you a big number
just a though
Like I said, I'm not touching the integer at all. The parameter that's screwing up is ignoreIndex. It happens direct after the first for loop, before the following if statement evaluates.
bool TestPlacement(CS200::Polygon2D* tP, int ignoreIndex, CS200::Polygon2D* parent) { // check for collisions bool collision = false; // circles test for (int i=0; i<static_cast<int>(gCircleList.size()); i++) { // ignore child objects during collision test if (gCircleList->parent != parent) { collision = CollisionTest(tP, gCircleList); if (collision) break; } } if (!collision) { // polygon test for (int i=0; i<static_cast<int>(gPolygonList.size()); i++) { // ignore self and child objects during collision test if (i != ignoreIndex && gPolygonList->parent != parent) { collision = CollisionTest(tP, gPolygonList); if (collision) break; } } } return collision;}
And as a sidenote, if I add this at the start of the function:
The debugger reports the following for each value at the end of the function:
Nice and random.
int test1 = ignoreIndex;int test2 = ignoreIndex;
The debugger reports the following for each value at the end of the function:
Quote:
ignoreIndex: 4307031
test1: 4571380
test2: -858993460
Nice and random.
Cripes, nevermind... I rebuilt the project and it's magically working now. I gotta remember to start doing that when I get these kinds of random problems.
Surreal. Well, good to hear you got it working. I certainly can't see any reason, at a glance, for that to happen.
Are you perhaps using Visual C++ 6? We used to have magic "rebuild all" problems with that version. I haven't had that problem with Visual Studio 2003 at all.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement