#unordered_map find triggers Segment Fault

11 messages · Page 1 of 1 (latest)

obtuse marsh
#

I have the following class and when the schedule method tries to execute find, internally it reaches out to .empty method which triggers a Segment Fault error because of the inner current_sizevariable (debug view says: <read memory from 0xf0000000788 failed (0 of 8 bytes read)>):

template <std::size_t N>
using TimelineEvent = etl::vector<Event, N>;

template <std::size_t S, std::size_t N>
using Arrangement = etl::unordered_map<unsigned int, TimelineEvent<N>, S, S>;

template <std::size_t S, std::size_t N>
class Timeline
{
private:
    Transport* transport_;
    Arrangement<S, N> arrangement_;
    etl::deque<unsigned int, S> timeline_;

public:
    Timeline(Transport* transport) : transport_(transport), arrangement_() {}
    ~Timeline() = default;

    //copy
    Timeline(const Timeline&) = delete;
    Timeline& operator=(const Timeline&) = delete;

    // move
    Timeline(Timeline&&) = delete;
    Timeline& operator=(Timeline&&) = delete;

    void schedule(Event event)
    {
        if(arrangement_.find(event.time) != arrangement_.end())
        {
            arrangement_[event.time] = TimelineEvent<N>{event};

            auto it = etl::lower_bound(timeline_.begin(), timeline_.end(), event.time);

            timeline_.insert(it, event.time);
        }
    }
...

Usage example:

Timeline<4, 2> timeline{&transport};

timeline.schedule({{0, n8}, {0, n4}, {n4, n2}, {n2, n1}});

Any ideas why?

steady duneBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
knotty moth
#

I don't see current_size there.

obtuse marsh
#

current_size is a variable inside .empty which is part of the unordered_map implementation. .find uses .empty internally

south hatch
#

do you have a repo with some of this code in there? i was going to try to replicate it on my end until i noticed you're using non-STL containers (are those from the embedded template library?). if you can provide an easy way to run an example I can take a look to see if anything stands out.

obtuse marsh
#

Thanks for the help @south hatch . I've figured out that the problem was to due with my call to .schedule which should make use of etl::move (analogous to std::move). Unfortunately debugging only made it worse, since the stack trace pointed in a completely different direction.

steady duneBOT
#

@obtuse marsh Has your question been resolved? If so, type !solved :)

obtuse marsh
#

!solved

steady duneBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

south hatch