Phass, I had surrendered, since I do not understand the code (and the language).
But, given the extremity of the situation I made some progress that may be useful to you. Using your backtrace to deduce the input I reproduced the behavior you describe: the program either hangs or crashes.
First, following advice regarding memory faults, I eliminated all warnings that appear with the
gcc -Wall -Wextra options. Particularly, I eliminated all warnings for functions that have possible control path without return statement, because allegedly those are source of such crashes. Even if you are certain, you just can not leave functions like that. Also, I inserted casts for the result of all size() functions to int. And so on.
Indeed, that solved nothing. You seem to have successfully avoided dynamic memory management, so the next step was to search for buffer overflow. Fortunately gcc has some helpful options:
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC. (Just discovered them.) I will have to research them additionally, but among other things they add indexing bounds checks for the vector containers. And, as expected, index out of bounds, namely a negative one showed up.
I caught the negative index in the
void Poblacion :: Mutacion (Individuo &), in the line:
|
ind.parametros_reales[k - prob_booleano - 1] = parametro;
|
To catch it yourself, I suggest you compile with the fore-mentioned options (
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC). Next, what I did (I don't know if this is the right approach) is to define the function:
1 2 3
|
void myabort (int) {
cerr << "abort handler called\n";
}
|
just before
int main () and inserted the code:
|
signal(SIGABRT, myabort);
|
right after the beginning of
main. This is necessary, because it allows you to set breakpoint in
myabort. The index checks are probably assert-ed and
abort is called. I do this for the first time, so there may be better ways. You will need to include
<csignal> in order to use the
signal function.
The issue is probably missing initialization. I have not investigated it further.
Here are the values of the locals in
void Poblacion :: Mutacion (Individuo &) when the situation occurs:
k 0
parametro 0.0304727331
prob_booleano 7
prob_total 86
|