Skip to main content
gamedev.net
🔒 Locked

Vector Problems

Started by Shyft777 7 replies 500+ views
Original Post
Shyft777
Shyft777
My program uses vectors for different things, and normally it works fine, but one particular vector refuses to have anything added to it. Every time I try to add something, it spits out an Unhandled Exception and crashes. Does anyone know how this could happen? My variable is a pointer to a class, but it''s never mined that before. Thanks Shyft
Epp
Epp
Can you post the code?
C-Junkie
C-Junkie
does your class''s copy constructor work properly?
JohnBolton
JohnBolton
Is the pointer valid?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
C-Junkie
C-Junkie
doh! just noticed the "pointer to" part...

what the vector''s .size() before and after push_back() ?
Shyft777
Shyft777
C-Junkie, the problem I''m having is that it doesn''t actually get past the adding part
The line it actually errors on is in the vector itself:

iterator end()
{return (_Last); } //<-- Unhandled Exception

The pointer itself seems to be correct.. I''ve tried assigning the pointer to a temporary class and adding that. The data in the temp variable is right, but it errors when I try to add temp.

I''ve tried a couple different things to test the problem, and it will let me add something to the list in the constructor, but not in any method. It also won''t add a temporary variable created in the same scope.

Here''s the code I''m using. HALMesh* is the class pointer I''m attempting to add, and HALList is wrapper around a vector. The add() method on the HALList simply calls push_back(). The () operator returns the item in position I.


void AddFrames(HALList<HALMesh*> FrameList)
{
for(int I=0; I<FrameList.Size(); I++)
{
HALMesh* Temp = FrameList(I);
Keyframes.add(Temp); //<--Errors here

}
return;
}


I appreciate the help!
Shyft
Maega
Maega
Have you tried doing

HALMesh *Temp = new HALMesh();
Temp = FrameList(I);
Keyframes.add(Temp);

Shyft777
Shyft777
LOL, I figured it out. This method is in another class called HALAnimationBase, and I never created a new one of those, so the Keyframes object is never initialized. Dumb mistake, but a deadly one

Thanks to everyone for their input, it''s good to know there''s a lot of competent people on these boards!

Cheers,
Shyft

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.