Segmentation fault on vectors.

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5

67 Replies - 1919 Views - Last Post: 20 August 2019 - 03:48 PM Rate Topic: -----

#61 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7020
  • View blog
  • Posts: 23,840
  • Joined: 05-May 12

Re: Segmentation fault on vectors.

Posted 18 August 2019 - 05:44 PM

Xrey274: I think that the extra information from the error messages that jimblumberg is looking for is to see if there are any warnings prior to the error you are getting, and to find out exactly which line the error is being reported on.

It would help dramatically if you could just give us a minimal repro case for the issue instead of having us wade through all your code.
Was This Post Helpful? 0
  • +
  • -

#62 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7020
  • View blog
  • Posts: 23,840
  • Joined: 05-May 12

Re: Segmentation fault on vectors.

Posted 18 August 2019 - 05:55 PM

For example, the following doesn't seem to reproduce the problem that you are encountering.
#include <vector>

class Shape
{
};

class Segment
{
    std::vector<Shape> m_dots;

public:
    std::vector<Shape>& getDots()
    {
        return m_dots;
    }
};

class Line
{
    std::vector<Segment> m_segments;

public:
    Line()
    {
        m_segments.push_back(Segment());
    }

    std::vector<Shape>& getLineDots()
    {
        return m_segments[0].getDots();
    }
};

int main()
{
    Line line;
    auto dots = line.getLineDots();
    return 0;
}


Was This Post Helpful? 0
  • +
  • -

#63 Xrey274   User is online

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 290
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 19 August 2019 - 10:36 AM

It's line 5 in the Resources class code snippet.

Quote

std::vector<sf::CircleShape>& Resources::getLineDots()
{
//lines is a vector of type FreeDraw(class)

return lines[0].getDots(); //this line
}

Was This Post Helpful? 0
  • +
  • -

#64 jimblumberg   User is offline

  • member icon

Reputation: 5745
  • View blog
  • Posts: 17,601
  • Joined: 25-December 09

Re: Segmentation fault on vectors.

Posted 19 August 2019 - 12:13 PM

Quote

It's line 5 in the Resources class code snippet.

Like I said you're not providing enough content.

How and where is lines defined?

What exactly does your error message state? Are there any other warnings prior to this one?

How exactly are you compiling this source? What compiler flags are you using?

Jim
Was This Post Helpful? 0
  • +
  • -

#65 Xrey274   User is online

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 290
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 20 August 2019 - 08:22 AM

Edit: Removed it as I have figured out the error and have fixed it - that being said with my current code the moment I try to open the program I get a segmentation fault. I am giving you this link where all .cpp and .h files are located.

This post has been edited by Xrey274: 20 August 2019 - 08:48 AM

Was This Post Helpful? 0
  • +
  • -

#66 Xrey274   User is online

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 290
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 20 August 2019 - 11:10 AM

The segmentation fault has since been fixed as well. Link is now not needed, but still active is you want to critique my bad code design/practices. :D
Was This Post Helpful? 0
  • +
  • -

#67 Xrey274   User is online

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 290
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 20 August 2019 - 03:13 PM

Thank you all for your help! :)
Was This Post Helpful? 0
  • +
  • -

#68 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7020
  • View blog
  • Posts: 23,840
  • Joined: 05-May 12

Re: Segmentation fault on vectors.

Posted 20 August 2019 - 03:48 PM

Out to curiosity, what caused the error?
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5