[Bug] getMaterialPageName option

Bekas

20-09-2006 22:36:38

The code for the getMaterialPageName option is
// convert position
Vector3 *pos = static_cast < Vector3 * > (pDestValue);
mPageManager->getGlobalToPage (pos->x, pos->z);

// get the texture
Ogre::PagingLandScapeTexture* texture_ptr =
mTextureManager->getTexture(pos->x, pos->z, false);

// check for valid texture
if( texture_ptr )
{
// get texture name
String* name_ptr = const_cast<String*>(&texture_ptr->getMaterialName());

// convert void pointer to a string**
String** target_ptr = static_cast<String**>(pDestValue);

// save name at target position
*target_ptr = name_ptr;
}

And its usage is this
Ogre::Vector3 p (mPos);
void* myOptionPtr = &p;

app->mSceneMgr->getOption ("getMaterialPageName", myOptionPtr);
std::string terr_mat = **static_cast<std::string**>(myOptionPtr);



The bug is that PLSM accepts a Vector3* and then it writes the string* pointer inside the Vector3 contents, messing it up.

It would be better if it accepted a Vector3** like this:
// convert position
Vector3 *pos = *static_cast < Vector3 ** > (pDestValue);
mPageManager->getGlobalToPage (pos->x, pos->z);
...............

And its usage would be like this:
Ogre::Vector3 p (mPos);
void* myOptionPtr = &p;

app->mSceneMgr->getOption ("getMaterialPageName", &myOptionPtr); // &myOptionPtr instead of myOptionPtr
std::string terr_mat = *static_cast<std::string*>(myOptionPtr);


That way the Vector3 doesn't get messed up, the string* pointer is written to myOptionPtr; the Vector3 will contain the x,z values set by getGlobalToPage.

tuan kuranes

21-09-2006 10:35:30

thanks for reporting and proposal.
Fixed in cvs and soon in next SDK.