Original Post
I am using an array of pointers to sprites like this: Sprite* _pBrickSprites[_iNumBrickRows][_iNumBrickCols]; And then I go through and initialize each like this: In detecting collisions I use this code: Everything compiles fine, but the line where I assign brickRect the position causes the game to crash. I have no clue why. This is the declaration of GetPosition() and the rect in the sprite class: RECT m_rcPosition; RECT& GetPosition() { return m_rcPosition; }; I have a feeling it has something to do with the reference being returned, but I can't figure it out. Thanks for any help.
for(int i=1; i<=_iNumBrickRows; i++)
{
for(int j=1; j<=_iNumBrickCols; j++)
{
_pBrickSprites[j] = new Sprite(_pBrickBitmap);
_pBrickSprites[j]->SetPosition(_pGame->GetWidth()*j/(_iNumBrickCols+1) - _pBrickBitmap->GetWidth()/2,
_iVerticalBrickSpacing*i + _pBrickBitmap->GetHeight()*(i-1));
_pGame->AddSprite(_pBrickSprites[j]);
}
}
// Loop through and check if the ball hit any of the bricks
RECT brickRect;
for(int i=0; i<_iNumBrickRows; i++)
{
for(int j=0; j<_iNumBrickCols; j++)
{
brickRect = _pBrickSprites[j]->GetPosition();
}
}