I am working on a game. At some places, sometimes I receive a segmentation fault and at all other times the code works properly. If I run the game again (after receiving segmentation fault) it recovers back (without any code changes) and runs fine. But after some time again this happens.
I tried debugging it using GDB. I got the following information:
- there is a function call : func(&s.x), where s is a structure and x is its member of type int. The address (&s.x) is 0xb3456721
- In function func the value received in the argument is 0xb.
- The program crashes saying memory at 0xb cannot be accessed. When I print the variable using GDB, I again receive memory cannot be accessed.
Any ideas Why this would happen?
A program that crashes sometimes but not other times when given identical input has a non-deterministic data source in it. Usually the source is an uninitialized variable or block of memory, but it could be dependence on a timestamp, process ID, or other source of input from the system that varies.