strange vector problem.

Started by
2 comments, last by Laroche 21 years, 3 months ago
I have a vector declared as a private member in class CScript, called: std::vector InstructionVector; In the constructor of CScript, i call InstructionVector.reserve(100); so far so good. But, later on in my program, before I push anything into it (actually even if i push anything in it), I call InstructionVector.capactity() and it crashes, telling me that I have an access violation. The same goes if I call InstructionVector.operator[], InstructionVector.begin(), or anything else. What could be the problem?
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Advertisement
Looking at the wrong direction. The vector isn't your problem.
It crashes because your CScript instance is broken.

Check if you accidently deleted it without setting the pointer
to 0 and access this dead pointer.
Maybe you overwrite parts of the CScript instance while loading some stuff into it?

In any case - debug and check if the CScript instance you're using is valid at all. I had a similar problem today (though it was a little more sublte since the crash appeared WAY off the
bug location ...) and was also stuck searching at the wrong place.

A general advice: if it crashes and you _know_ it usually _cannot_ then the problem lies somewhere else and you just observe the symptoms as it crashes rather than the root of the problem

[edited by - darookie on January 19, 2003 7:50:02 PM]
But i also _know_ that the script instance _cannot_ be broken because I'm using it in other areas as well, even if it's only calling small functions which dont do much.

EDIT: Eventually I'll learn not to ignore what I don't think is the problem is and actually listen. You were right, the script object WAS broken, I was attempting to execute the script commands before having loaded them Thanks for the useful tips.

[edited by - laroche on January 19, 2003 8:16:57 PM]
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
quote:Original post by Laroche
... But, later on in my program, before I push anything into it... What could be the problem?

err.. like these:

CScript *pcs = new CScript;
...
delete pcs;
..
pcs->DoSomething()


or


CScript& SomeF()
{
CScript cs;
..
return cs;
}

???

or....

Guess you screwed up some memory thingy.
"after many years of singularity, i'm still searching on the event horizon"

This topic is closed to new replies.

Advertisement