<im*****@hotmail.co.ukwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Daniel T. wrote:
>Like I told you before (in the thread titled "bus error, resize vector",
you are going outside the bounds of one of your vectors. Put asserts in
to find out which one.
What is actually happening in my code is quite complicated and I did
not explain it correctly.
Essentially I have two vectors, the first is getting corrupted in some
way causing a spurious integer to be written to one of the elements.
This integer is then being used to index another vector and that is
where the error is becoming visible. So I know which vector is being
incorrectly indexed, but I don't know where this value is coming from.
So, you found where the invalid index was being used to access a vector.
And then you found that that index was coming from the value _stored_ in
another vector. Correct? Ok, now you have to find out how those value get
stored into that vector in the first place. Something in your code is
writing an invalid value there. But we have no way of knowing where that
invalid value comes from. We can't see your code (since you haven't posted
it here).
It probably gets there because you write it there, with push_back for
example. Or, it may get there because you've got broken code elsewhere.
But we certainly can't tell from here.
You need to either learn to use your debugger, or else post a minimal,
compilable, example here which demonstrates the problem.
Or, you could go back to your code and analyze where it's wrong. Look
especially at the places where you write to the vector. How do you make
sure that the values in that vector are valid indexes into the other vector?
(And how do you know that they _remain_ valid later in the program?)
You could add assert statements where you write to the vector, which make
sure that the value you're writing is a valid index into the other vector.
That might show you if you attempt to put a bad value there. (But it won't
tell you if that value is still good later. If you delete stuff from the
other vector, for example, then how do you handle indexes that point at the
deleted stuff?)
And if you're 100% absolutely positively sure that the code which writes
those index values to the vector is correct, and will never ever write an
invalid value, and that those values will always _remain_ valid, then the
problem just may be somewhere else entirely. Perhaps you're overwriting
memory somewhere, such as writing past the end of an array (including
C-style strings, which are just char arrays). Or perhaps you're
dereferencing a pointer to a deleted object. We have no way of knowing.
Only you can tell, by examining your code, or by using your debugger, or by
posting code here which exhibits the problem.
-Howard