Game Development Community

Adding Vector<> to fxSceneObject2D crashes

by Gregory Stewart · in Torque Game Builder · 08/23/2005 (8:37 pm) · 3 replies

Ok, so I've added a Vector, where fsmState is a simple struct with no constructor or destructor. Now, I've added a ConsoleMethod called addState to fxSceneObject2D which creates a fsmState and then calls v.push_back( state ), where v is the Vector and state is an instance of fsmState. However, at this point in the code, the program crashes. Apparently, upon calling push_back(), the Vector resizes itself and this is causing a crash (specifically, free() is being passed an invalid memory block header).

Does anybody have any idea what I could be doing wrong? Do I need to initialize the Vector<> somehow?

Thanks guys!

-Greg

#1
08/24/2005 (12:07 am)
From what you've described, it should work fine.

The following should work.

struct fsmState
{
  U32 mode;
};

Vector<fsmState> v;
fsmState state;
state.mode = 1;
v.push_back(state);

Unfortunately, my only suggestion would be to do a clean/build.

- Melv.
#2
08/24/2005 (2:00 am)
Melv, I appreciate the response. I actually just found out what I was doing wrong. The fsmState structure actually looked like this:

struct fsmState
{
     S32 stateID;
     Vector<S32> inputs;
     Vector<S32> outputs;
};

Anyways, I didn't think about the fact that these Vector<>'s would need their constructors called... so, excuse my mistake and thanks again for your help.

-- Greg
#3
08/24/2005 (5:36 am)
Glad it's working. :)

- Melv.