Skip to content

Commit 086a11a

Browse files
committed
TopMenu/Water: Fixed hydrax crashing on nd start
still very glitchy though, and crashes upon return to main menu (during rendering - invalid pointer to listener)
1 parent d2f7ed1 commit 086a11a

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

source/main/gfx/HydraxWater.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,38 @@ HydraxWater::HydraxWater(float water_height, Ogre::TerrainGroup* terrain_grp, Og
4242
, waterHeight(water_height)
4343
, waveHeight(water_height)
4444
, CurrentConfigFile(conf_file)
45+
, mTerrainGroup(terrain_grp)
4546
{
4647
App::GetCameraManager()->GetCamera()->setNearClipDistance(0.1f);
4748

4849
InitHydrax();
4950

5051
//Apply depth technique to the terrain
51-
TerrainGroup::TerrainIterator ti = terrain_grp->getTerrainIterator();
52+
TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
5253
while (ti.hasMoreElements())
5354
{
55+
// getNext() advances the iterator
5456
Ogre::Terrain* t = ti.getNext()->instance;
55-
MaterialPtr ptr = t->getMaterial();
56-
mHydrax->getMaterialManager()->addDepthTechnique(ptr->createTechnique());
57+
MaterialPtr tMat = t->getMaterial();
58+
mHydrax->getMaterialManager()->addDepthTechnique(tMat->createTechnique());
5759
}
5860
}
5961

6062
HydraxWater::~HydraxWater()
6163
{
64+
//Remove depth technique from the terrain
65+
TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
66+
while (ti.hasMoreElements())
67+
{
68+
// getNext() advances the iterator
69+
Ogre::Terrain* t = ti.getNext()->instance;
70+
MaterialPtr tMat = t->getMaterial();
71+
for (Ogre::Technique* technique: tMat->getTechniques())
72+
{
73+
mHydrax->getMaterialManager()->removeDepthTechnique(technique);
74+
}
75+
}
76+
6277
mHydrax->remove();
6378
mHydrax = nullptr;
6479
}

source/main/gfx/HydraxWater.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class HydraxWater : public IWater
6262
Hydrax::Noise::Perlin* waternoise;
6363
Hydrax::Module::ProjectedGrid* mModule;
6464
Ogre::String CurrentConfigFile;
65+
Ogre::TerrainGroup* mTerrainGroup; //!< For cleanup only
6566
};
6667

6768
/// @} // addtogroup Gfx

source/main/gfx/hydrax/MaterialManager.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -3368,6 +3368,26 @@ namespace Hydrax
33683368
}
33693369
}
33703370

3371+
void MaterialManager::removeDepthTechnique(Ogre::Technique *Technique)
3372+
{
3373+
Ogre::Pass *DM_Technique_Pass0 = Technique->getPass(0);
3374+
ROR_ASSERT(DM_Technique_Pass0);
3375+
if (!DM_Technique_Pass0)
3376+
{
3377+
return;
3378+
}
3379+
3380+
if (DM_Technique_Pass0->getVertexProgramName() == _def_Depth_Shader_VP_Name)
3381+
{
3382+
DM_Technique_Pass0->setVertexProgram(""); // Remove vertex shader
3383+
}
3384+
3385+
if (DM_Technique_Pass0->getFragmentProgramName() == _def_Depth_Shader_FP_Name)
3386+
{
3387+
DM_Technique_Pass0->setFragmentProgram(""); // Remove fragment shader
3388+
}
3389+
}
3390+
33713391
void MaterialManager::addDepthTechnique(Ogre::Technique *Technique, const bool& AutoUpdate)
33723392
{
33733393
if (!Ogre::MaterialManager::getSingleton().resourceExists(_def_Depth_Material_Name))

source/main/gfx/hydrax/MaterialManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ namespace Hydrax
255255
return mOptions;
256256
}
257257

258+
/** Undo `addDepthTechnique()`
259+
*/
260+
void removeDepthTechnique(Ogre::Technique *Technique);
261+
258262
/** Add depth technique to an especified material
259263
@param Technique Technique where depth technique will be added
260264
@param AutoUpdate The technique will be automatically updated when water parameters change

0 commit comments

Comments
 (0)