I've been trying to debug this for a while and sadly I'm not even sure if overflow itself is the problem or what...
I've narrowed it down somewhat to a single line (and some other similar lines) that quickly
lead to the program crashing, but the lines themselves do not necessarily cause crashing.
(Cnode->Value[0])=(Cnode->Value[0])*(Cnode->Value[0]);
(the other 'similar lines' are for addition, subtraction, and division)
Value[] is an array of floats, 9 all together. They are part of a class (Node), which are dynamically allocated during run time - could easily be hundreds of nodes. Nodes are processed in an indefinite loop (while the ESC key is not pressed) and so that line is easily run hundreds of times per second per node for an indefinite amount of time.
To be sure I wasn't accidentally going out of bounds, I specified 0 (normally I used Variable%8) for the index of the array.
When I comment out that line, the program does not crash - easily running for 12 hours at a time. By contrast, crashing, when it happens, is extremely likely to occur within 5 seconds. Confusingly, those variables are being used in other ways. To be clear, the nodes are part of a 'neural network' and thus the contents of these variables are being sent back and forth via links to other nodes all the time:
Clink->To->Prevalue[Clink->Valto%8]+=Cnode->Value[Clink->Valfrom%8]/Cnode->Value[NODEVAR];
This line is run for each node, sending data to all connected nodes. This line has never lead to crashing that I'm aware of - it has been around long before that first one I showed.
I thought it might have been overflow - maybe the variables were just 'counting too high'? So I tested it with this:
1 2 3 4 5 6
|
float* Poibug;
*Poibug=2;
while(esc not pressed)
{
(*Poibug)=(*Poibug)*(*Poibug);
}
|
This has never lead to crashing. Crashing is, however, somewhat random, but like I said, it's
extremely common to happen within 5 seconds. I've left the program running for half an hour at a time or more, just to be as sure as I can be.
When I changed the variables in the nodes to short int, from float, crashing does not occur.
Also, I do a lot of typecasting. For example, typecasting those floats in the nodes, as unsigned char, or int. Can that cause problems, and how can it? I've never noticed it causing crashing before.
I would be extremely happy to help you help me, so if more information is required, just ask and I will give, even the full source code if it need to be.