Witam.
Jakieś pomysły, dlaczego wywala mi segfault w momencie wywołania std::vector::clear()? Jest to vector prostych obiektów, bez żadnych wskaźników czy innych tego typu historii. Debugger wskazuje na plik stl_vector.h, na funkcję:
/**
* Erases all the elements. Note that this function only erases the
* elements, and that if the elements themselves are pointers, the
* pointed-to memory is not touched in any way. Managing the pointer is
* the user's responsibility.
*/
void
clear() _GLIBCXX_NOEXCEPT
{ _M_erase_at_end(this->_M_impl._M_start); }
Sam vector to std::vector <Segment> body;, gdzie Segment jest zdefiniowany jako:
enum class Direction
{
up,
down,
right,
left,
};
class Segment
{
public:
Segment();
Segment(int x, int y, Direction dir, int block_size);
bool intersect(const Segment &s) const;
int get_x() const;
int get_y() const;
int get_size() const;
Direction get_direction() const;
void move_forward();
void move_backward();
void change_position(int x, int y);
void set_position(int x, int y);
void change_direction(Direction direction);
private:
uint8_t pos_x, pos_y, size;
Direction dir;
};