Hi Xiao,
After some days on holidays I have been integrating the new terrain in my application. I have detected some things:
First, I use the function "TerrainGroup::RayResult TerrainGroup::rayIntersects(const Ray& ray, Real distanceLimit /* = 0*/) const" in order to get the distance to the terrain in the direction which the camera point to. Depending on both the camera speed and the distance to the terrain I manage the camara movement. The problem ocurrs when, in seldom occasions, I get a crash. I guess it is related with intersection whit an terrain page no fully loaded. In other occassions the function did not crash but returned a rayResult value incoherent (ie, the hit = true when the terrain pointer do not point to a valid terrain instance).
Second, I have experienced some crash with the default AutoUpdateLodByDistance strategy, due to the the obtained vieport pointer had a null pointer to camera:
Code: Select all
const Viewport* vp = terrain->getSceneManager()->getCurrentViewport();
if(!vp)
return;
const Camera* cam = vp->getCamera()->getLodCamera();
The statement terrain->getSceneManager()->getCurrentViewport() gets the current viewport being rendered, and due to the asynchronous nature of the autoUpdateLod system could be some arbitrary conflicts, mainly if the sceneManager uses several vieports for different renders.
I solved this using a custom strategy obtaining the main camera pointer from the CameraManager of my application and both the vieport and the lodCamera from the mainCamera:
Code: Select all
const Ogre::Viewport* vp = mainCamera->getViewport();
if(!vp)
return;
const Ogre::Camera* cam = mCamera->getLodCamera();
The result is now perfectly stable. Other approach could be to add the camera pointer as an argument of the autoUpdateLodByDistance(Terrain *terrain, bool synchronous, const Real holdDistance) function.
Another problem I have experienced is related with the custom strategy implementation. It was imposible for me to derive the new strategy from a Singleton Template for second time and from a diferent dll without getting link errors. I had to modify the original code deriving directly from Ogre::Singleton only the TerrainAutoUpdateLodByDistance from which I have to derive.
Code: Select all
class _OgreTerrainExport TerrainAutoUpdateLod // now do not derive from Ogre::Singleton
class _OgreTerrainExport TerrainAutoUpdateLodByDistance : public TerrainAutoUpdateLod, public Singleton<TerrainAutoUpdateLodByDistance>
Best regards,