There is a difference between:
| high_entity *EntityHigh = 0;
if(...)
{
EntityHigh = ...;
// ... other code
}
return(EntityHigh);
|
and this code:
| high_entity *EntityHigh = 0;
if(...)
{
high_entity *EntityHigh = ...;
// ... other code
}
return(EntityHigh);
|
Do you see the difference? Try to answer to yourself why there is a difference before reading further.
Your fragment of code has two EntityHigh variables. If you put return inside if statements, you will be returning the "inner" EntityHigh. If you have return statement at end of function (outside if statement), you will be returning the "outer" EntityHigh (the one which is defined at beginning of function.
Most likely you want to change "high_entity *EntityHigh = &GameState->HighEntities[HighIndex];" into "EntityHigh = &GameState->HighEntities[HighIndex];". This will assign new value to existing EntityHigh pointer, instead of defining new EntityHigh variable.
And yes, that inner EntityHigh variable really goes out of scope, when you are stepping over the "return" line if it is at bottom of function. This was just a bug in the code, no need to reinstall whole Visual Studio in these kind of situations. It's almost always bug in the code, and not a issue with VS installation.