Archived

This topic is now archived and is closed to further replies.

Laroche

strange vector problem.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites