[SOLVED] crashing TreeLoader3D::deleteTrees()

hyperjingun

30-01-2008 09:00:17

hi-

I need some help.

std::vector<TreeDef> &treeList = _getGridPage(pageGrid, tileX, tileZ);
std::vector<TreeDef>::iterator i;
for (i = treeList.begin(); i != treeList.end(); ){
//Get tree distance
float distX = (gridBounds.left + (tileX * pageSize) + ((Real)i->xPos / 65535) * pageSize) - pos.x;
float distZ = (gridBounds.top + (tileZ * pageSize) + ((Real)i->zPos / 65535) * pageSize) - pos.z;
float distSq = distX * distX + distZ * distZ;

if (distSq <= radiusSq){
//If it's within the radius, delete it
*i = treeList.back();
treeList.pop_back();
modified = true;
}
else
++i;
}

this source code was error when Visual studio .net 2005.

Error was "Vector iterator incompatible".

And I use PagedGeometry 1.03 version.

Is same position between vector::back() and vector::end() ?

please help~ T_T

JohnJ

31-01-2008 19:51:18

Are you saying that it's not compiling, or that deleteTrees() is crashing? Can you post the segment of code you used to call deleteTrees() so I can test?

hyperjingun

01-02-2008 01:22:43

hi-

I said deleteTrees() is crashing.

my code is:

//create TreeLoader3D, and setPageLoader.

//m_pEnt was just 'ninja.mesh" entity.
treeLoader->addTree(m_pEnt, Ogre::Vector3(50.0f, 0.0f, 50.0f));

treeLoader->deleteTrees(Ogre::Vector3(50.0f, 0.0f, 50.0f), 0.0f); <- crash.

VC8 was occured error that "Vector iterator incompatible"

and change code "*i = TreeList.back(); TreeList.pop_back()" into

"i = TreeList.erase(i)" will solve this problem.

But i`m not convinced this solution...

JohnJ

01-02-2008 01:34:39

Ok, thanks for the info - I'll check it out.

JohnJ

03-02-2008 00:15:45

I reproduced and fixed the problem. You can get the latest version from CVS.

hyperjingun

04-02-2008 00:31:45

Thank you very much!

Have a good day~ :)