Page 1 of 1

bug in Samples code

Posted: Fri Aug 18, 2017 5:19 pm
by ArbitraryValue
In Samples/2.0/Common/include/GameEntity.h, there is the following code:

Code: Select all

bool operator < ( const GameEntity *_r ) const
{
    return mId < _r->mId;
}
It is used in GameEntityManager::removeGameEntity, which has the following line:

Code: Select all

GameEntityVec::iterator itor = std::lower_bound( mGameEntities[toRemove->mType].begin(),
                                                 mGameEntities[toRemove->mType].end(),
                                                 toRemove );
This doesn't work. (See, for example, https://stackoverflow.com/questions/141 ... to-objects.)

I suggest removing the deceptive overloaded operator < and replacing it with this function:

Code: Select all

static bool Compare(const GameEntity *_l, const GameEntity *_r)
{
    return _l->mId < _r->mId;
}
Then in GameEntityManager::removeGameEntity, write

Code: Select all

GameEntityVec::iterator itor = std::lower_bound( mGameEntities[toRemove->mType].begin(),
                                                 mGameEntities[toRemove->mType].end(),
                                                 toRemove,
                                                 GameEntity::Compare);
Note that none of the samples ever call GameEntityManager::removeGameEntity, but for someone attempting to build on the framework presented in the tutorial this bug will be a problem.

Re: bug in Samples code

Posted: Sat Aug 19, 2017 2:11 am
by dark_sylinc
Oh my!
Yes, that's a silly bug.

Edit: Fixed. Thanks for the report!