bug in Samples code

Minor issues with the Ogre API that can be trivial to fix
Post Reply
ArbitraryValue
Gnoblar
Posts: 14
Joined: Tue Mar 22, 2011 10:06 pm

bug in Samples code

Post 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.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5292
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: bug in Samples code

Post by dark_sylinc »

Oh my!
Yes, that's a silly bug.

Edit: Fixed. Thanks for the report!
Post Reply