Most Random Bug
I have discovered quite a bug in my program. In the program I run some collision checking, output the coordinates, and draw a point where the collision occurred. I have found my collisions to be quite accurate so I decided to stop outputing the coordinates, but when I do that, the collisions stop working. Put the line back in and it works. In the code below, the line with the arrow pointing at it is the line causing it. If the line is in the code, the collisions work perfectly. If I take it out, they stop working right. I don't get it. Has anyone ever had such a weird bug in their programs? How could I fix this?
Code:
void CheckAllCollisions()
{
for(int i=0; i<myPlayer.GetWeapon(myPlayer.GetCurWeapon()).GetMaxAmmo(); i++)
{
if(CheckCollision(myMesh,myPlayer.GetWeapon(myPlayer.GetCurWeapon()).GetBullet(i),collision[i]))
{
-----------> cout << "(" << collision[i].GetX() << ", " << collision[i].GetY() << ", " << collision[i].GetZ() << ")" << endl;
myPlayer.DeactivateBullet(i);
}
}
}
Agreed. The implementations of GetX, GetY, and GetZ are critical. I suspect that one or all of them has a side effect.
Other things that you can try, if you suspect that it's something quirky about how that specific code is compiling (which I have seen once or twice before) would be to output something that doesn't involve GetX, GetY, or GetZ... also the other way around... assign the results of GetX, GetY, and GetZ (in different combinations if that helps narrow down the problem) into unused variables and don't output them. That should tell you whether it's these methods or the debugging output that is causing the behavior you're seeing.
Other things that you can try, if you suspect that it's something quirky about how that specific code is compiling (which I have seen once or twice before) would be to output something that doesn't involve GetX, GetY, or GetZ... also the other way around... assign the results of GetX, GetY, and GetZ (in different combinations if that helps narrow down the problem) into unused variables and don't output them. That should tell you whether it's these methods or the debugging output that is causing the behavior you're seeing.
And you are keeping the myPlayer.DeactivateBullet(i); even when you remove the cout right? That could be another place with a side effect.
One other thing - have you tried completely rebuilding your project?
One other thing - have you tried completely rebuilding your project?
GetX,Y, and Z simply are return statements that return the X,Y, or Z coordinate (as a float value).
Yes I'm keeping the deactivate bullet function when I'm removing the cout.
I haven't tried rebuilding the project yet.
Yes I'm keeping the deactivate bullet function when I'm removing the cout.
I haven't tried rebuilding the project yet.
Exact code can be critical with these problems, I would copy and paste all relevant functions into this forum. Also double check any arrays which may be allocated 'close to' this function. When you have weird errors like this it could be a sign of stack or heap corruption. If you experience intermittent crashes in memory allocation routines like malloc, realloc, or free, that is a strong sign of heap corruption.
I'd also suggest a clean compile; although it may seem like "whatever may ail you, clean compile", I've had Xcode throw a fit, compiling code in a comment block before...
Mark Bishop

