Skip to content

Commit

Permalink
[Regression] Fix Terra crash if trying to assign a datablock more tha…
Browse files Browse the repository at this point in the history
…n once
  • Loading branch information
darksylinc committed Aug 28, 2021
1 parent 57a74f0 commit 1cbc489
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions Samples/2.0/Tutorials/Tutorial_Terrain/src/Terra/Terra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,6 @@ namespace Ogre
accumDim += maxPixelDimension * (1u << iteration);
++iteration;

if( !m_terrainCells[0].empty() && m_terrainCells[0].back().getDatablock() )
{
HlmsDatablock *datablock = m_terrainCells[0].back().getDatablock();
OGRE_ASSERT_HIGH( dynamic_cast<HlmsTerra *>( datablock->getCreator() ) );
HlmsTerra *hlms = static_cast<HlmsTerra *>( datablock->getCreator() );
hlms->_unlinkTerra( this );
}

for( size_t i = 0u; i < 2u; ++i )
{
m_terrainCells[i].clear();
Expand Down Expand Up @@ -755,6 +747,15 @@ namespace Ogre
//-----------------------------------------------------------------------------------
void Terra::setDatablock( HlmsDatablock *datablock )
{
if( !datablock && !m_terrainCells[0].empty() && m_terrainCells[0].back().getDatablock() )
{
// Unsetting the datablock. We have no way of unlinking later on. Do it now
HlmsDatablock *datablock = m_terrainCells[0].back().getDatablock();
OGRE_ASSERT_HIGH( dynamic_cast<HlmsTerra *>( datablock->getCreator() ) );
HlmsTerra *hlms = static_cast<HlmsTerra *>( datablock->getCreator() );
hlms->_unlinkTerra( this );
}

for( size_t i = 0u; i < 2u; ++i )
{
std::vector<TerrainCell>::iterator itor = m_terrainCells[i].begin();
Expand All @@ -767,9 +768,12 @@ namespace Ogre
}
}

OGRE_ASSERT_HIGH( dynamic_cast<HlmsTerra *>( datablock->getCreator() ) );
HlmsTerra *hlms = static_cast<HlmsTerra *>( datablock->getCreator() );
hlms->_linkTerra( this );
if( mHlmsTerraIndex != std::numeric_limits<uint32>::max() )
{
OGRE_ASSERT_HIGH( dynamic_cast<HlmsTerra *>( datablock->getCreator() ) );
HlmsTerra *hlms = static_cast<HlmsTerra *>( datablock->getCreator() );
hlms->_linkTerra( this );
}
}
//-----------------------------------------------------------------------------------
Ogre::TextureGpu* Terra::_getShadowMapTex(void) const
Expand Down

0 comments on commit 1cbc489

Please sign in to comment.