0

I'm making a game with bullet physics where I have a Platform class, which contains a btBoxShape, btDefaultMotionState and a btRigidBody as members. When exiting my game it crashes. I store the Platform objects in an std::vector, and I think this is the problem. When I push back more Platforms, the vector resizes and moves in memory. This means that whatever pointer to the shape and motionstate that the rigid body has is invalidated. How should I solve this?

2 Answers2

2

A std:deque will not invalidate the references.

0

There are a couple of options I can think of.

std::array/std::vector with a fixed size(reserve()), if possible

std::vector<Platform*> You should probably use smart pointers here, but basically allocate yourself and store just pointers in the vector.

Karthik T
  • 31,456
  • 5
  • 68
  • 87