I have a class, C. C has a member variable declared as: bool markerStart;
From within C a call to sizeof(*this) gives a value of 0x216 bytes.
Elsewhere within C, I do: markerStart = false;
Rather than setting markerStart to false, this call is actually clobbering the start of the next class in memory!
Looking at the disassembled code, I find:
markerStart = false;
06FB6B7F mov eax, dword ptr [this]
06FB6B78 mov byte ptr [eax+218h], 0
The second move instruction is setting a byte at this + 0x218 to zero, but since the class is only 0x216 bytes long, this is clobbering memory!
In response to a comment, it definitely is the markerStart = false instruction. I can watch it happening in the disassembler view and in the memory view (and using Windbg, by using a data breakpoint). The first byte of the next class gets set to zero, which messes up its vftbl pointer.
Note: taking the address of markerStart and subtracting it from this, yields 0x211!
Can anyone give me a clue on where to start looking to resolve this problem?
Update: Thanks for all the help. Without code, it was next to impossible for any of you to solve the problem. What I was looking for were hints as to where to start looking. Most of you provided excellent hints, so thank you!
I finally found the problem. In this case alignment had been set in one class, and not been correctly reset following the critical block of code. The class with the faulty alignment happened to get compiled immediately before the declaration of class C - hence that's where the problem showed up.