virtual float HealthRechargeRate() const { return 0.2f; }; virtual float ShieldRechargeRate() const { return 1.0f; }; virtual float GetTankSpeed() const { return 2.0f; }; virtual float TurnPerPower() const { return 45; }; virtual float GetMaxRange() const { return 70.0f; }; virtual float GetMinRange() const { return 50.0f; }; virtual float GetTransitionTime() const { return 2.0f; };They work fine in most cases, except in my terrain rendering file, terrain.cpp. If they are used anywhere in terrain.cpp, if you call one of them it calls the next one instead. For example, if I call GetMaxRange() the debugger will step into GetMinRange() instead. If I call GetTransitionTime() it just crashes. It returns the other function's value so I know it's not just the debugger messing up, and it's causing visual bugs in my terrain rendering procedures. There are other virtual functions in this class but they all work fine, it's only this block of functions that behave improperly. Moving them somewhere else in the class definition doesn't help. Moving the inline function definition into the class's .cpp file doesn't help. Making them not virtual fixes the problem, but obviously I need them to be virtual. The problem doesn't occur in any other files. I also looked in the vftable through VS's debugger, and didn't see any of these functions present for some reason.
I thought it was some kind of strange memory overwriting problem, but then I examined the disassembler. In every file where the functions behave correctly, the virtual function call for GetMaxRange() looks like this:
006FDA34 mov eax,dword ptr [edx+94h] But for terrain.cpp it looks like this:
006FDA34 mov eax,dword ptr [edx+98h] It's four bytes off. So it's definitely a compile-time problem and not a runtime problem. I've examined the preprocessor generated file (the .i file) and it has the correct call in it so I don't think it's a preprocessing problem. The problem didn't always occur, it started when I added some networking into the game, which involved some extensive changes to the way objects are created and destroyed.
Any ideas?