This very weird problem is driving me nuts. If I create new variables, all drawing stops working even though I don't make any changes to this part of my code. If I create still more, drawing works again as if nothing happened. Can anyone explain this? This only happens when variables are initialized upon declaration and, stranger yet, only in a certain area. The variables are not even used or referenced, just created. This problem is very weird and seems to point to a bug in VC++ 2008 Express. Here are plenty of examples of what I'm witnessing. For starters, this bit of code has drawing working fine:

Code:
... includes, defines, etc. ...
... other variables ...
int GoodZone = 4;
int StillGoodZone = 8;
... more variables ...
If I add more variables, not bothering to reference them or anything, just initialize, all of a sudden, drawing stops working.

Code:
... includes, defines, etc. ...
... other variables ...
int GoodZone = 4;
int StillGoodZone = 8;
int BadZone = 12;
int StillBadZone = 16;
... more variables ...
Weirder yet, if I add even more variables, things work fine again:

Code:
... includes, defines, etc. ...
... other variables ...
int GoodZone = 4;
int StillGoodZone = 8;
int BadZone = 12;
int StillBadZone = 16;
int BackToGoodZone = 20;
... more variables ...
Stranger yet that, if I move these variables to another section of the code, everything still works without problems:

Code:
... includes, defines, etc. ...
int GoodZone = 4;
int StillGoodZone = 8;
int BadZone = 12;
int StillBadZone = 16;
... other variables ...
... more variables ...
Getting even weirder, if I use an array instead and initialize it, everything still works:

Code:
... includes, defines, etc. ...
... other variables ...
int TestArray[4] = {4, 8, 12, 16};
... more variables ...
Shrink the array to size 3 and things stop working. Shrink the array to size 1 and things work again. Increase the array size to 10 and things stop working again. Increase it to 12 and thing work again. Even as far out to 25, things still work. If I don't initialize the array, it always works regardless of the size.

Even weirder yet is that, if I declare the variables, don't initialize them upon declaration, and set them in a function, I have no problems.

Code:
... includes, defines, etc. ...
... other variables ...
int GoodZone;
int StillGoodZone;
int BadZone;
int StillBadZone;
... more variables ...

void InitializeVariables()
{
   GoodZone = 4;
   StillGoodZone = 8;
   BadZone = 12;
   StillBadZone = 16;
}
If I use a different variable type, like the char or __int64, this problem still occurs in the same way, though it takes a different number of variables before this happens, pointing to memory alignment issues.

Code:
... includes, defines, etc. ...
... other variables ...
short GoodZone = 4;
short StillGoodZone = 8;
short BadZone = 12;
short StillBadZone = 16;
// short BackToGoodZone = 20; // uncomment this to make drawing fail
... more variables ...
Does anyone have any explanations on this? There seems to be an 8-byte zone where things stop working. Could there be a bug with VC++ 2008 Express or a memory leak that I have no idea if it exists or not? Unfortunately, I have no idea how to find memory leaks outside the whole program crashing or looking/behaving weird.