Friday, October 1, 2010

Segfault caused by std::vector copying?

Since the early days of cataclysm, I've been getting this annoying segfault that I just couldn't figure out.  The backtrace didn't end, like most segfaults do, with me trying to access an out-of-bounds address; rather, it descended through 10 calls in stl_vector.h and ended with a few in cmov.  Today it finally dawned on me that they all had the same thing in common; copying a vector.  Something along the lines of
std::vector<point> plans2 = plans;
would always be at the root of the problem (the backtrace also produced erroneous line numbers, for some reason, making it hard to debug).  Having replaced these lines with stuff like
std::vector<point> plans2; 
for (int i = 0; i < plans.size(); i++)
I hope I've solved the issue for good, and eradicated my  last known segfault.  This should reduce crashes to 1% of what they used to be!

No comments:

Post a Comment