richelbilderbeek / djog_unos_2018

Project by the Uno's at DJOG 2018-2019: Nature Zen
GNU General Public License v3.0
6 stars 2 forks source link

Use asserts instead of couting a segfault #500

Closed richelbilderbeek closed 5 years ago

richelbilderbeek commented 5 years ago

Is your feature request related to a problem? Please describe.

I find here:

void game::remove_tile(...) 
{
  //...
  try {
    if(m_tiles[i].get_id() == m_selected.at(0)){
       m_selected.pop_back();
    }
  } catch (std::out_of_range) {
    std::cout << "segmentation fault\n";
  }
}

This is problematic for multiple reasons:

Describe alternatives you've considered

Add asserts and use the operator[] instead:

  assert(i < static_cast<int>(m_tiles.size());
  assert(0 < static_cast<int>(selected.size())
  if(m_tiles[i].get_id() == m_selected[0]){
     m_selected.pop_back();
  }

Additional context

None.