attilaszia / nonogram

A C++ implementation for solving the nonogram constraint satisfication problem. Among a few naive ones, the dynamic programming algorithm discussed in K. J. Batenburg , W. A. Kosters Solving Nonograms by combining relaxations - is implemented.
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.177.76&rep=rep1&type=pdf
9 stars 3 forks source link

Segmentation fault when using example sherrif_puzzle #3

Closed richelbilderbeek closed 7 years ago

richelbilderbeek commented 7 years ago

Thanks for adding the examples!

Too bad, it gives a segfault:

In the examples folder:

richel@lubuntu:~/GitHubs/nonogram/examples$ ../solver sheriff_puzzle.txt 
Pic-a-Pix solver 0.1
Initializing solver with: sheriff_puzzle.txt
Initializing a table with sheriff_puzzle.txt
Segmentation fault (core dumped)

In the root folder:

richel@lubuntu:~/GitHubs/nonogram$ ./solver examples/sheriff_puzzle.txt 
Pic-a-Pix solver 0.1
Initializing solver with: examples/sheriff_puzzle.txt
Initializing a table with examples/sheriff_puzzle.txt
Segmentation fault (core dumped)

I volunteer to fix it.

To do so, I will add Travis CI to my fork (I have some experience with it) to test if the examples do work. Feel free to remove the Travis status badge, but all you'll need to do to join in on the Good Practices, is register at https://travis-ci.org (it's free and two clicks if you use your GitHub account). Sure, I volunteer to maintain it.

Additionally, I will add a qmake project file called nonogram.pro. Sure, I volunteer to maintain it.

I hope you agree on the extra goodies I'll give you for free. If not, let me know.

attilaszia commented 7 years ago

Hm, thats weird, it works for me just as fine as the others. Anyways, thank you for the overall effort, it is of course very welcome :)

richelbilderbeek commented 7 years ago

(attilaszia: no need to read this, this is a note for myself)

Found the cause:

bool Table::Init(std::string filename){
  std::cout << "Initializing a table with " << filename << "\n";
  std::ifstream f;
  std::string line;
  f.open(filename.c_str());
  assert(f.is_open());

  int lastindex = filename.find_last_of("."); 
  raw_filename_ = filename.substr(0, lastindex); 

  if ( f.is_open() ) {
    if ( getline (f,line) ){

      std::stringstream  linestream(line);
      // Setup width, and height 
      linestream >> width_;
      linestream >> height_;

      assert(height_ > 0);
      assert(height_ < 1'000'000'000);
    }
    // Setup cols 
    for (int i=0; i<width_; i++){
      getline (f,line);
      std::vector<int> linedata; 
      std::stringstream linestream(line);
      int value;
      while ( linestream >> value ) {
        linedata.push_back(value);
        assert(linedata.size() < 1'000'000);
      }
      assert(height_ > 0);
      assert(height_ < 1'000'000'000); //HERE
      Line* current_col = new Line(linedata, height_);
      current_col->set_type(kColumn);
      current_col->j(i);
      cols_.push_back( current_col );
      heap_.push( current_col );
    }
  //...
}

2017-04-11-154017_1600x1200_scrot

Leading hypothesis:

richelbilderbeek commented 7 years ago

Works now locally and on Travis, without any bug actually found. May be a Heisenbug. Close anyways.