Re: std::vector clear() causes segmentation fault?
On 2007-10-30 18:48, Bryan wrote:
Hello all. I'm fairly new to c++. I've written several programs
using std::vectors, and they've always worked just fine. Until today.
The following is a snippet of my code (sorry, can't include all of it-
it's over 1k lines long). In addition, I'm including an "include"
file where structures like "stack" are defined. Again, it's really
long. I doubt the problem lies there, though, because the include
file is used in many other programs, all of which work fine.
[snip code]
Notice how the segmentation fault occurs right after "About to reset
for a new set of swaths." and the message "Successfully reset for a
new set of swaths." never appears. I believe this means that the
statement "multiple_swaths_indices.clear();" must be causing the
segmentation fault.
Does anyone know why this is happening? I've been staring at this
code for nearly a week now, and I don't have ANY idea why it's
crashing. I've been inserting cout statements like crazy, trying to
identify anything strange, but everything looks normal as far as I can
tell...
If the segfault occurs when calling std::vector<T>::clear() it means
that either your implementation of the standard library is buggy or that
you have a problem in one of your destructors. Since the probability of
a problem with the implementation is near zero I thing you have a
problem with the destructor of the class that were stored in the vector.
Probably the class contains a pointer which is dereferenced in some way
during destruction, and that pointer is no longer valid.
As bjeremy said, by running it through a debugger you should be able to
find the exact place of the problem.
--
Erik Wikstr??m