Weird first chance exceptions with STL vectors in C++

K.I.L.E.R

Retarded moron
Veteran
First-chance exception at 0x00401a33 in Robot.exe: 0xC0000005: Access violation reading location 0xbaadf011.
Unhandled exception at 0x00401a33 in Robot.exe: 0xC0000005: Access violation reading location 0xbaadf011.
The program '[496] Robot.exe: Native' has exited with code -1073741819 (0xc0000005).

Can someone tell me what reasons would my code throw this kind of exception in relation to vectors(STL)?
It only complains when I "list->push_back(s);".
 
K.I.L.E.R said:
Can someone tell me what reasons would my code throw this kind of exception in relation to vectors(STL)?
It only complains when I "list->push_back(s);".

Basically you're writing to either uninitialised or free'd memory. Most likely culprit is a bad list *, but your code fragment is far from exhaustive.

I don't remember which way round MS's default sentinel fills are. BAADF011 is one of them. In none release builds memory is filled when it's allocated, or freed.
 
I figured I'd create the vector like everything else.

Code:
private:
    vector<Spatial> *list;

public:
    ObjectHolder(void)
    {
        Spatial s = Spatial();
        list->push_back(s);
    }
 
Gizz, I originally wrote details in my first message, but I must have done something wrong since they aren't here :(

I mean that you might be calling a function on a NULL or invalid pointer.

Your " vector<Spatial> *list;" is never newed in your code sample, if you want to use it without newing it, then just write "vector<Spatial> list;", it'll be automatically allocated on object creation.

While I'm at it:
Code:
private:
    vector<Spatial> list; //you most likely want to give it a REAL name :p

public:
    ObjectHolder(void)
    {
        list->push_back( Spatial() ); //not a dramatic change but if you do nothing with it...
    }
 
This thing is giving me the shits.
Thanks guys, it now works except for something causing it to fail.

HEAP[Robot.exe]: Invalid Address specified to RtlFreeHeap( 003F0000, 003F25F0 )
Unhandled exception at 0x7c901230 in Robot.exe: User breakpoint.

I do not recall ANY breakpoints in my or any other code.
 
K.I.L.E.R said:
This thing is giving me the shits.
Thanks guys, it now works except for something causing it to fail.



I do not recall ANY breakpoints in my or any other code.
Probably generated by an assert in whatever library you are using.
Something that is worth doing is looking at the call stack in your debugger (an often under used feature), have a look at the line that is going wrong.
It will almost certainly be accessing an invalid pointer.
Look at where is that pointer setup, check to see if something is corrupting the pointer.

Basically you want to track down the cause of the assertion by a process of elimination.

CC
 
Thanks. I have a new love for Java (Even C isn't this bad). :???:

I found the problem, it's when I add things into my list.

Problem solved.
It's probably going to give me diarrhea.

My Spatial class had it's "Point" as a pointer instead of a reference.
What this meant was that whenever my variable went out of scope it would call "delete".
 
C++ is a powerful language, and just like any power tools, misuse or failure to understand it completely brings disastrous results.
 
Previous post made me remember:
"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." - Bjarne Stroustrup.
 
C++'s problems isn't power. It's the horribly user interface, because that's what a language is in many respects, and it's crap.

Take all the power of C++ except use a syntax, with little things like CFG, and smart defaults for behaviour -- of course it should be overridable.
 
I'd have to agree.
C++ doesn't lend itself very much towards productivity when compared to smart languages such as C# and Java.
 
Saem said:
C++'s problems isn't power. It's the horribly user interface, because that's what a language is in many respects, and it's crap.

Take all the power of C++ except use a syntax, with little things like CFG, and smart defaults for behaviour -- of course it should be overridable.

Of course the design of C++ has a lot to do with compatibility with C, and that's probably the most important reason why C++ is popular (heavily used by many). I think that if C++ does not have to be compatible with C, it may have better syntax. However, even with a better syntax, a language this powerful is still likely to be dangerous. C++ in its current form is dangerous even to beginners who don't use its advanced functions (actually, mostly dangerous to C users since they tend to have false assumptions on C++). A better language design should be more safe to beginners, but I think current C++ almost have that if the beginner knows some simple rules (like avoiding pointers).

Unfortunately, current development directions of C++ is still going to a more advanced way, as in TR1. Beginners can use these cool new developments without complete understanding, but they (and sometimes even professional programmers) will eventually be bitten by the lack of some knowledge.
 
I like C++, though. I also like C# syntax, but I don't like the lame-ass .NET and the "speed":rolleyes: of the whole package thus its of no interest to me.
 
On a side note digitalmars "D" language is rather cute, compiler available, dunno about speed though.
 
pcchen,

I think a language can be as powerful as one wants and it's fine. Look people operate very dangerous heavy machinery all the time and the reason it works out well most of the time is that a lot of effort has gone into making sure the operator knows what they're doing and the interface to it doesn't suck -- read, not a mine field of gotchas.
 
Saem said:
I think a language can be as powerful as one wants and it's fine. Look people operate very dangerous heavy machinery all the time and the reason it works out well most of the time is that a lot of effort has gone into making sure the operator knows what they're doing and the interface to it doesn't suck -- read, not a mine field of gotchas.

I think this is the key point. :)
 
pcchen said:
I think this is the key point. :)

Blah, you jerk! ;)

I know that's important, but that goes hand in hand with the fact that they don't make an operator hostile interface. =P
 
Back
Top