Segmentation fault on multimap iterator

I have created a multimap for my road points. The key refers to the road number and the values are vec3 points that make up the road.

I am trying to iterate through the values of each key point and create a road segment at each point on the road (except the last), adjust the values to be on the road points and then store them in a std::vector.

The RoadSegment constructor creates 6 vec3 points and pushes them onto a std::vector.

I have a segmentation fault in the line marked in bold
[for(mapIt = it.first; mapIt != it.second; ++mapIt)]

When i take out the lines creating the new objects and pushing them onto the std::vector it works fine.

Can anyone tell me what the problem is / a solution to the problem??

Many thanks in advance.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

    std::vector<glm::vec3>::iterator SegIt;


    for(int i = 0; i < m_genRoads->getKeyValueData().size(); i++)
    {
        int numberDesired = m_genRoads->getMultimapData().count(i) - 1;

        std::multimap<int, glm::vec3>::iterator mapIt;
        std::pair<std::multimap<int, glm::vec3>::iterator, std::multimap<int, glm::vec3>::iterator> it;

        it = m_genRoads->getMultimapData().equal_range(i);


        for(mapIt = it.first; mapIt != it.second; ++mapIt)
        {

            int distance = std::distance(it.first, mapIt);

            if(distance != numberDesired)
            {
                RoadSegement* roadSegmentPointer = new RoadSegement();

                // FUNCTIONS TO ADJUST COORD VALUES TO MATCH THE ROAD POINTS
                

                m_segmentArray.push_back(roadSegmentPointer);

            }

            else
            {
                continue;
            }

             ///SOME BUFFER BINDING STUFF 
Last edited on
i've not used multipmaps, but what's the value of it.second when you hit line 15?
Topic archived. No new replies allowed.