Strange run time error

It's been quite sometime since I last coded in C++ perhaps half a year ago.
Anyway, as far as I can remember these are the causes of run time error : too deep stack call, 1/0, access memory that is not suppose the be accessed. so I coded a modified BFS and this a runtime error occur then I hit the debugger.

This particular code is the source of run time error
this code is in some function and not in main
 
   if( results[i][walk_count] == currentCoordinate ) return 2;


These are the types
1
2
3
4
const vector<vector<pair<int,int>>>& results;
int i;
int walk_count;
const pair<int,int> currentCoordinate;


the code have make sure that it is not accessing the out of place index
1
2
3
4
5
6
7
8
		for( unsigned i = 0; i < crafts.size(); ++ i ){
			if( results[i].size() == 0 ){
				if( crafts[i].cx == x && crafts[i].cy == y ) return 1;
				continue;
			}
			if( results[i].size() >= walk_count && results[i].back() == currentCoordinate ) return 1;
			if( results[i][walk_count] == currentCoordinate ) return 2;
		}


so what could have caused it ?
Where is the assurance that crafts.size() <= results.size() and/or that walk_count < results[i].size()?
crafts.size is always equal to results.size
because results is created based of crafts.size
sorry if that is not explicitly written

and oh yeah about the walk_count < results[i].size();

so I change it to this
1
2
3
4
5
6
7
8
9
10
11
			if( results[i].size() == 0 ){
				if( crafts[i].cx == x && crafts[i].cy == y ) return 1;
				continue;
			}
			
			if( results[i].size() >= walk_count ){
				if( results[i].back() == currentCoordinate ) return 1;
				continue;
			}
			
			if( results[i][walk_count] == currentCoordinate ) return 2;


to make sure that walk_count < results[i].size();
but the same rte is still happening, but now the debugger won't say exactly where ...
I am sorry that I can't really use a debugger I just hit F8 and hope that it show some useful info
If the code reaches line 11, walk_count > results[i].size() will be true because you've discarded all other possibilities on line 6.
Oh yeah I misread what happened on line 6
Thank you for your guidance
Last edited on
Topic archived. No new replies allowed.