I'm implementing collision resolution with two AABB's but it seems "if(*yDepth > 0)" is being completely skipped by the compiler. When i apply a breakpoint to the statement within visual studio it replies "this breakpoint will not currently be hit. Is it an issue with pointers? I have tried moving the contents of the statement, changing conditions, but it seems to always skip the if statement in question.
Vector2* normal = new Vector2();
Vector2* vFrom1to2 = new Vector2();
*vFrom1to2 = Vector2(b->getX() - a->getX(), b->getY() - a->getY());
float* xDepth = new float();
*xDepth = (a->getWidth()) + (b->getWidth()) - abs(vFrom1to2->x);
float* yDepth = new float();
if (*xDepth > 0) {
*yDepth = (a->getHeight()) + (b->getHeight()) - abs(vFrom1to2->y);
std::cout << "break";
if (*yDepth > 0) { //this statement is skipped completely. yDepth is greater than 0 on testing.
if (xDepth < yDepth) {
if (vFrom1to2->x < 0) {
normal->x == -1;
normal->y == 0;
}
else {
normal->x == 1;
normal->y == 0;
}
}
else {
if (vFrom1to2->y < 0) {
normal->x == 0;
normal->y == -1;
}
else {
normal->x == 0;
normal->y == 1;
}
}
}
}
In release mode - or more precisely, when optimisation is on - the compiler can re-order, re-arrange, combine or even remove lines of code. This means that there is no longer a one to one correspondence between the lines of code you wrote and the machine code that is actually produced. This can mean that certain lines of code can no longer have breakpoints assigned to them and the debugger may skip around when stepping through your code.
Usually, it is better to debug in debug mode for this reason. If this is not possible, set a breakpoint near the line you are interested in and step through the code from there rather than on the exact line you are interested in.
(Note to readers: the asker clarified in a comment that they are experiencing this problem in release mode)