Why does this Object wonk out & get deleted ?

Posted by brainydexter on Stack Overflow See other posts from Stack Overflow or by brainydexter
Published on 2010-04-10T08:11:52Z Indexed on 2010/04/10 8:13 UTC
Read the original article Hit count: 321

Filed under:
|
|

Stepping through the debugger, the BBox object is okay at the entry of the function, but as soon as it enters the function, the vfptr object points to 0xccccc. I don't get it.

  1. What is causing this ?
  2. Why is there a virtual table reference in there when the object is not derived from other class. (Though, it resides in GameObject from which my Player class inherits and I retrieve the BBox from within player. But, why does the BBox have the reference ? Shouldn't it be player who should be maintained in that reference ?)

For 1; some code for reference:

A. I retrieve the bounding box from player. This returns a bounding box as expected. I then send its address to GetGridCells.

const BoundingBox& l_Bbox = l_pPlayer->GetBoundingBox();

boost::unordered_set < Cell*, CellPHash >& l_GridCells = GetGridCells ( &l_Bbox );

B. This is where a_pBoundingBox goes crazy and gets that garbage value.

boost::unordered_set< Cell*, CellPHash > CollisionMgr::GetGridCells(const BoundingBox *a_pBoundingBox) {

I think the following code is also pertinent, so I'm sticking this in here anyways:

const BoundingBox& Player::GetBoundingBox(void) { return BoundingBox( &GetBoundingSphere() ); }

const BoundingSphere& Player::GetBoundingSphere(void) { BoundingSphere& l_BSphere = m_pGeomMesh->m_BoundingSphere;

l_BSphere.m_Center = GetPosition();

return l_BSphere; }

// BoundingBox Constructor BoundingBox(const BoundingSphere* a_pBoundingSphere);

Can anyone please give me some idea as to why this is happening? Also, if you want me to post more code, please do let me know.

Thanks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about programming