An odd bug where a guard clause around a loop causes the code work. Without it we get an access violation. I did not report this when I first found it as I managed to work around it using the below but it has now cropped up somewhere else in the same codebase and the same workaround can be used.
I did output (to a message box) the address and value of the variable to verify this. This will be a terrible one to isolate as the codebase is large and not well formed. I mention it in case it rings any bells as it would be good to get to the bottom of.
/* Don't remove the following conditional, it works around an issue in 64 bit.
** If you check the address of the_number before this loop and then after
** this loop, it changes. It gets restored on exit of the routine though.
** Placing this conditional here gets the compiler to not do whatever it was
** doing and the address stays the same, meaning no crashes.
*/
if (the_number > 0)
{
for(int i = 0; i <the_number; i++) {
the_elements_backup[i] = the_elements[i];
}
}
Happy to share more info if you are interested.