I save each grid cell as an integer. Players die when they move into a tile with a nonzero value.
But evil nonzero integers just popped out of nowhere and killed the innocent players.
Now I finally fixed this bug. Here is the bad code:
Code:
typedef enum {
D_RIGHT=0,
D_DOWN=1,
D_LEFT=2,
D_UP=3
} Direction;
#define ROTATE_CW(dir) (((dir)+1)%4)
#define ROTATE_CCW(dir) (((dir)-1)%4)
gcc thinks 0%4 is 0, while VS apparently blows up and corrupts everything. Yup, I was relying on undefined behaviour.
I have spent about 1 hour coding the game itself and like 10 hours on searching this bug. Now I feel myself stupid, but also a winner.
Like always after fixing a bug.
Bookmarks