So I am going through all my usual bug hunting techniques, and it made me think it might be worthwhile starting a thread about problems that are hard to find.
So here's a couple I can think of straight away.
1) Works on {insert platform here} but not on {insert other platform here}
The first thing I look for in this case is an uninitialized member variable. On PC when you create a new instance of an object the memory allocated for it is often full of zero's. On other platforms the memory can just be filled with random data. This can be a really tricky bug to find, but if you observe the bug closely you can often get a clue as to which variable is the problem.
This bug can also be called Works for {insert time here} then goes wrong.
In this case it can happen when the game runs out of unused memory and starts reusing memory that has been allocated before.
2) Works for {n} objects but doesn't work for {m}
It is common for objects to be lumped together. The c++ way is to have a base class and then derive other classes off the base class. However before we had c++, it was common to use structs for objects. To make the objects adaptable, we used unions.
struct GameObject
{
int ID;
union
{
char * name;
float fname;
int iname;
}u;
}GameObjectt;
That's fine as it is, however this can be fatal on some platforms.
Consider this variation on the above code.
struct GameObject
{
int ID;
char fred;
union
{
char * name;
float fname;
int iname;
}u;
}GameObjectt;
Looks fine doesn't it? Well it's a potential disaster.
Some compilers will look at that and create a structure like this.
ID 0x0000 fred 0x0004 u 0x0005 size 0x0009
Ow dear..... if you access name, all is fine. Access fname or iname and the game crashes.
This is because a lot of platforms can only pick up a pointer from an aligned address. This does not apply to a char * as the compiler knows that a sizeof(char) can be one, so adds extra code to handle this case.
There are a lot of ways to fix this, gcc has alignment macros you can add to the end of a struct, other compilers have command line switches, but the best thing to do is rewrite the code to bring it up to date.
Well that's two from me, one obvious, one obscure. Anybody got any more?













