mercredi 8 août 2018

C++17 Variable seems to be changed inside if statement

I have a weird bug in my code that I can't make any sense of. I have a variable with an assigned value prior the conditional statement. Somehow the variable is assigned the value it is being compared to inside the if statement.

At first I thought it was just my mistake using '=' instead of '==' but that's not the case.

Here is my debug screens before stepping into the conditional

enter image description here

see that px and img[y][x] are both 1.

Now as soon as I step into the if statement, it all changes to 0 and I get stuck inside the while loop.

enter image description here

Can anyone please explain what happened between these steps? In my debugging, it jumps straight from line 227 to 229 in a single step so I don't know what is happening in between. Also, once it enters the while loop, the only variable I see are x, y, and x0. Shouldn't px and img still exist in this scope?

Is there a better way to approach this? I just want to make sure that my start point is actually a white pixel before I start counting the blanks.

I'm using VC15 if that's of any relevance.

Aucun commentaire:

Enregistrer un commentaire