Segmentation fault in std function std::_Rb_tree_rebalance_for_erase ()

不打扰是莪最后的温柔 提交于 2019-12-06 20:17:29

Possibly you're holding onto an iterator into ce across the call to recover. If recover happens to remove that item the iterator will be invalidated and any future use (say an attempt to erase it) could result in a seg fault.

It would help if we could see more context of how ce is used before and after the call to recover.

The problem was that on line 426 of Simulation.cpp, I tried to delete an event in the EventPQ currentEvents (a.k.a. ce) container that my recover() function had just deleted. The iterator had obviously been invalidated. Dumb.

Lessons:

  • Debug on code that has not been optimized
  • Pay close attention to what the non-std related frames imply

And for the future: Trace memory in valgrind

I'm still stumped why the debugger referred me to an apparently blank line in stl_tree.h.

I've massive appreciation here for the people who have helped me work through this. I'm going to revise my question so it's more concise for any future readers.

Perhaps the call to assert is not compiled with your configuration. Assertions in production code are usually a Bad Idea[TM].

You could also be exceeding immune's boundaries.

Try:

    if (epqItr != ce.end()) 
    {
        ce.erase(epqItr);
        if (z is within immune's bounds)
        {
            ++immune[z]; 
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!