@@ -28,7 +28,7 @@ class CEffectClonerImpl : public CEffectCloner
2828 virtual void ReleaseD3DEffect ( ID3DXEffect* pD3DEffect );
2929
3030 // CEffectClonerImpl
31- void MaybeTidyUp ( bool bForceDrasticMeasures = false );
31+ void MaybeTidyUp ( bool bForceDrasticMeasures = false , CEffectTemplate* pKeepThis = NULL );
3232
3333 CElapsedTime m_TidyupTimer;
3434 CRenderItemManager* m_pManager;
@@ -102,32 +102,41 @@ ID3DXEffect* CEffectClonerImpl::CreateD3DEffect ( const SString& strFilename, co
102102 }
103103 }
104104
105+ static uint uiCallCount = 0 ;
106+ uiCallCount++;
107+
105108 // Need to create new EffectTemplate?
106109 if ( !pEffectTemplate )
107110 {
111+ SString strReport;
112+ HRESULT hr;
108113 for ( uint i = 0 ; i < 2 ; i++ )
109114 {
110- HRESULT hr;
111115 pEffectTemplate = NewEffectTemplate ( m_pManager, strFilename, strRootPath, strOutStatus, bDebug, hr );
112116 if ( pEffectTemplate || hr != E_OUTOFMEMORY || i > 0 )
113117 {
114- if ( i > 0 )
115- AddReportLog ( 7547 , SString ( " NewEffectTemplate - Free unused resources success! %s " , *strFilename ) ) ;
118+ if ( pEffectTemplate && i > 0 )
119+ strReport += " [ Free unused resources success] " ;
116120 break ;
117121 }
118122 // Remove unused effects from memory any try again
119- AddReportLog ( 7542 , SString ( " NewEffectTemplate E_OUTOFMEMORY - Attempting to free unused resources (%s) %s " , *strOutStatus, *strFilename ) ) ;
123+ strReport += " [ E_OUTOFMEMORY] " ;
120124 MaybeTidyUp ( true );
121125 }
122126 if ( !pEffectTemplate )
123127 {
124- AddReportLog ( 7544 , SString ( " NewEffectTemplate failed (%s) %s" , *strOutStatus, *strFilename ) );
125- return NULL ;
128+ strReport += SString ( " [failed %08x %s]" , hr, *strOutStatus );
129+ }
130+ else
131+ {
132+ // Add to active map
133+ MapSet ( m_ValidMap, ConformPathForSorting ( strFilename ), pEffectTemplate );
126134 }
127135
128- OutputDebugLine ( SString ( " [Shader] CEffectClonerImpl::CreateD3DEffect - New EffectTemplate for %s" , *strFilename ) );
129- // Add to active map
130- MapSet ( m_ValidMap, ConformPathForSorting ( strFilename ), pEffectTemplate );
136+ if ( !strReport.empty () )
137+ AddReportLog ( 7544 , SString ( " NewEffectTemplate (call:%d) %s %s" , uiCallCount, *strReport, *strFilename ) );
138+ if ( !pEffectTemplate )
139+ return NULL ;
131140 }
132141
133142
@@ -137,21 +146,28 @@ ID3DXEffect* CEffectClonerImpl::CreateD3DEffect ( const SString& strFilename, co
137146
138147 // Clone D3DXEffect
139148 ID3DXEffect* pNewD3DEffect;
149+ SString strReport;
150+ HRESULT hr;
140151 for ( uint i = 0 ; i < 2 ; i++ )
141152 {
142- HRESULT hr;
143153 pNewD3DEffect = pEffectTemplate->CloneD3DEffect ( strOutStatus, bOutUsesVertexShader, bOutUsesDepthBuffer, hr );
144154 if ( pNewD3DEffect || hr != E_OUTOFMEMORY || i > 0 )
145155 {
146- if ( i > 0 )
147- AddReportLog ( 7548 , SString ( " CloneD3DEffect - Free unused resources success! %s " , *strFilename ) ) ;
156+ if ( pNewD3DEffect && i > 0 )
157+ strReport += " [ Free unused resources success] " ;
148158 break ;
149159 }
150160 // Remove unused effects from memory any try again
151- AddReportLog ( 7543 , SString ( " CloneD3DEffect E_OUTOFMEMORY - Attempting to free unused resources (%s) %s " , *strOutStatus, *strFilename ) ) ;
152- MaybeTidyUp ( true );
161+ strReport += " [ E_OUTOFMEMORY] " ;
162+ MaybeTidyUp ( true , pEffectTemplate );
153163 }
154164
165+ if ( !pNewD3DEffect )
166+ strReport += SString ( " [failed %08x %s]" , hr, *strOutStatus );
167+
168+ if ( !strReport.empty () )
169+ AddReportLog ( 7544 , SString ( " CloneD3DEffect (call:%d) %s %s" , uiCallCount, *strReport, *strFilename ) );
170+
155171 if ( !pNewD3DEffect )
156172 {
157173 if ( strOutStatus.empty () )
@@ -239,7 +255,7 @@ void CEffectClonerImpl::DoPulse ( void )
239255// Tidy up if been a little while since last time
240256//
241257// //////////////////////////////////////////////////////////////
242- void CEffectClonerImpl::MaybeTidyUp ( bool bForceDrasticMeasures )
258+ void CEffectClonerImpl::MaybeTidyUp ( bool bForceDrasticMeasures, CEffectTemplate* pKeepThis )
243259{
244260 if ( !bForceDrasticMeasures && m_TidyupTimer.Get () < 1000 )
245261 return ;
@@ -250,7 +266,7 @@ void CEffectClonerImpl::MaybeTidyUp ( bool bForceDrasticMeasures )
250266 for ( uint i = 0 ; i < m_OldList.size () ; i++ )
251267 {
252268 CEffectTemplate* pEffectTemplate = m_OldList[i];
253- if ( pEffectTemplate->GetTicksSinceLastUsed () > ( bForceDrasticMeasures ? 0 : 1 ) )
269+ if ( pEffectTemplate != pKeepThis && pEffectTemplate ->GetTicksSinceLastUsed () > ( bForceDrasticMeasures ? 0 : 1 ) )
254270 {
255271 OutputDebugLine ( " [Shader] CEffectClonerImpl::MaybeTidyUp: Releasing old EffectTemplate" );
256272 SAFE_RELEASE ( pEffectTemplate );
@@ -271,7 +287,7 @@ void CEffectClonerImpl::MaybeTidyUp ( bool bForceDrasticMeasures )
271287 for ( std::map < SString, CEffectTemplate* >::iterator iter = m_ValidMap.begin () ; iter != m_ValidMap.end () ; )
272288 {
273289 CEffectTemplate* pEffectTemplate = iter->second ;
274- if ( pEffectTemplate->GetTicksSinceLastUsed () > ( bForceDrasticMeasures ? 0 : iTicks ) )
290+ if ( pEffectTemplate != pKeepThis && pEffectTemplate ->GetTicksSinceLastUsed () > ( bForceDrasticMeasures ? 0 : iTicks ) )
275291 {
276292 OutputDebugLine ( " [Shader] CEffectClonerImpl::MaybeTidyUp: Releasing valid EffectTemplate" );
277293 SAFE_RELEASE ( pEffectTemplate );
0 commit comments