terminate called throwing an exceptionAbort trap: 6
I am having difficulty finding a clear explanation of what this error is. This is making it difficult to debug. Can anyone point me to a clear explanation of this exception or can they explain it themselves with minimal jargon? Thanks.
void Network::findNetwork(int depth, int parent, int child){
//Vector initialization
if(network.size()<=parent && depth==0) network.resize(network.size()+1);
if(depth==0) tree.push_back(parent);
//base case when max depth is reached
if (depth==MAX_DEPTH) {
cout << "Max depth reached" << endl;
return;
}
//base case where all cells have been checked
elseif (parent>=cells.size()) {
cout << "All cells have been checked" << endl;
return;
}
//Recursive case where child is a significant contributor
elseif (cells[parent][child]==1){
std::vector <int> tmp;
bool inTree=false;
for (int i; i<tree.size(); i++){
if (tree[i]==child) inTree=true;
}
if (!inTree){
tree.push_back(child); //Keeps track of which values are higher in the tree
network[parent].push_back(child); //exception seems to be coming from here
findNetwork(depth+1,child,0);
tree.pop_back();
}
}
//Recursive case where next child should be considered
if (child+1<cells[parent].size()){
findNetwork(depth,parent,child+1);
}
}
An example of the kind of vector that cells would be
The exception would probably come from a bad allocation for a child being pushed back. My guess would be that your recursion went into an infinite loop and keeps trying to push back.
I would try a cout at line 2 to see how big these vectors are getting. Like Vlad says, it's hard to know exactly what your code is trying to do.
I'll look into the possible problems with an infinite loop.
As much as I wish I could write clearer code, I can't. :(
In words the 2-dimensional vector "cells" represents whether one row is connected to another row. A 0 means they are not connected and a 1 means they are connected. How connectedness is unimportant. I am trying to build a tree of connected rows. In the example above row 1 (cells[0]) is connected to rows 4 cells[3] and 5 cells[4]. I use this information to build a tree which keeps track of all connections between rows. This is later used to print output in another function.
I found the problem. It was indeed in line 3 and line 27. After two connections were found line 27 tried to push_back the network vector. However, because the condition in line 3 the first dimension of the network vector did not exist in order to push back the 2nd dimension. If line 3 is changed to the following code the problem is solved.