terminate called throwing an exceptionAbort trap: 6

 
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.

What code threw the exception? That would be helpful in seeing
Here is the code that produces the error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
	else if (parent>=cells.size()) {
		cout << "All cells have been checked" << endl;
		return; 
	} 
	
	//Recursive case where child is a significant contributor
	else if (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
1
2
3
4
5
cells[0]={0,0,0,1,1};
cells[1]={0,0,1,0,1};
cells[2]={0,1,0,1,0};
cells[3]={1,0,1,0,1};
cells[4]={1,1,0,1,0};


*Edited to correct a typo pointed out by vlad from moscow below
Last edited on
It seems that this statement is invalid

//Recursive case where child is a significant contributor
else if (cells[parent][child]=1){

Are you sure that instead of the comparision operator == you need to use the assignment oerator =?
You are right. That was not in the original code that generated the problem. I just deleted the extra '=' when I was cleaning up the code to post.
The problem is that your code is unclear. For example what does the vector tmp do?!

//Recursive case where child is a significant contributor
else if (cells[parent][child]==1){
std::vector <int> tmp;

I think that some operation with vectors generate the exception but it is difficult to say which operation because I do not know what you are doing.
Last edited on
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.
Last edited on
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.

 
if(network.size()==0) network.resize(cells.size());
Topic archived. No new replies allowed.