Collision function causing heap corruption?

Started by
12 comments, last by justin12343 12 years, 6 months ago

const std::vector<Object* const> GridCell::GetObjects()
{
std::vector<Object* const> list;
list.assign( mObjects.begin(), mObjects.end());
return list;
}


I rewrote this function, but I'm still getting this error. the mObjects vector is fine and so is all the objects. For some reason list is getting corrupted.
Advertisement
Although this may not solve your problem, for the sake of any level of efficiency at all, you should pass an std::vector as a reference to that function and return that same reference.


typedef std::vector<const Object *> ObjectList;




ObjectList & GridCell::GetObjects( ObjectList &list )
{
list.assign( mObjects.begin(), mObjects.end());
return list;
}



L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I don't see the need for the troublesome copying and/or moving from GridCell members to the output parameter that takes place in the GridCell::GetObjects method .
Can't you return read-only references or pointers to the original collection, or iterators of that collection, or the individual objects themselves? Even without memory corruption problems, these objects are owned by GridCell instances, and they shouldn't go anywhere else without a good reason.

Omae Wa Mou Shindeiru

I found the problem. PMASK was corrupting memory because the masks were initialized improperly. (FACE PALM)

This topic is closed to new replies.

Advertisement