Somewhere in this code is an error, Console closes like a segfault.

I cannot find the bug that is residing in this code, I've narrowed it down a lot.

This function resides in my main program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int draw_world(){
     mvprintw(0,0, "I Made it into draw_world()");
     refresh();
     getch();
     erase();
     refresh();
     for (int i = 0; i < LINES - 1; i++){
          for (int j = 0; j < COLS - 1; j++){
               mvprintw(0,0, "I started Counting!");
               refresh();
               mvprintw(1,0, "%i", world.test);
               refresh();
/**************This call seems to be the error, as it will print the world.test integer correctly.  
The program terminates as if it is getting a seg fault****/
               int c = world.get_terType(i, j);
               
               mvprintw(0,0,"%i", c);
               refresh();
               getch();
               erase();
          }
     }
     return 0;
}


World is an instance of the class area.

area.h
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
#ifndef AREA_H
#define AREA_H
#define EMPTY #
#define PLAINS =
#define MOUNTAINS ^
#define WATER ~
#include <vector>


/*
 * No description
 */
class area{   
     private:
          struct cell_t{
               int ter_type;
               bool passable;
          };
     std::vector <std::vector <cell_t> > map;
        
	public:
		// class constructor
		area(int y, int x);
		int get_terType(int y, int x);
                int test;
		// class destructor
		~area();
};

#endif // AREA_H 


area.cpp
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
#include "area.h" // class's header file

// class constructor
area::area(int y, int x){
    test = 1000;

     for (int i =0; i < y; i++){
          for (int j = 0; j < x; j++){
               map[y][x].ter_type=0;
               test +=1;
          }
     }
};
int area::get_terType(int y, int x){

     return (map[y][x].ter_type);
}        
	


// class destructor
area::~area()
{

}


This program uses the PDCurses library, (Same as Ncurses for unix users). and Vectors.
I'm just having issue after issue since I started trying to use vectors, maybe somebody who knows a little bit more can help?

Thanks!
Robert
Last edited on
What do you mean by "closes like a segfault"? Does it give you an error or does it is just close? Can you try to break it (go to where the error was) and look at the stack trace?
It simply closes, everytime I've seen this error on a unix box, the cli returns a segfault unfortunately I'm on a windows box, and i'm not to sure how to use the debug mode in my ide hence all the "I got here" statements in my code, the problem in my mind appears to be with my vector

< vector < cell_T> > map

This is my first time really playing with vectors, and I'm sure that I'm accessing it wrong or returning its value wrong, if you'd like I can post the entire program in a reply here to see if you can replicate the error.

I've tried using breakpoints but they just don't work properly in Dev-C++.
Topic archived. No new replies allowed.