Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when using example sherrif_puzzle #3

Closed
richelbilderbeek opened this issue Apr 11, 2017 · 3 comments
Closed

Segmentation fault when using example sherrif_puzzle #3

richelbilderbeek opened this issue Apr 11, 2017 · 3 comments

Comments

@richelbilderbeek
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

(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:

  • Windows file format used in the text files

@richelbilderbeek richelbilderbeek changed the title Segmantation fault when using example sherrif_puzzle Segmentation fault when using example sherrif_puzzle Apr 11, 2017
richelbilderbeek pushed a commit to richelbilderbeek/nonogram that referenced this issue Apr 11, 2017
richelbilderbeek pushed a commit to richelbilderbeek/nonogram that referenced this issue Apr 11, 2017
@richelbilderbeek
Copy link
Contributor Author

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

attilaszia added a commit that referenced this issue Apr 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants