@@ -35,6 +35,8 @@ void CElementDeleter::Delete ( class CClientEntity* pElement )
3535 // Add it to our list
3636 if ( !pElement->IsBeingDeleted () )
3737 {
38+ // Just to be clear, not a Lua event
39+ OnClientSpecialElementDestroy ( pElement );
3840 m_List.push_back ( pElement );
3941 }
4042
@@ -68,6 +70,8 @@ void CElementDeleter::DeleteRecursive ( class CClientEntity* pElement )
6870 // Add it to our list over deleting objects
6971 if ( !pElement->IsBeingDeleted () )
7072 {
73+ // Just to be clear, not a Lua event
74+ OnClientSpecialElementDestroy ( pElement );
7175 m_List.push_back ( pElement );
7276 }
7377
@@ -94,15 +98,14 @@ void CElementDeleter::DeleteIFP ( CClientEntity * pElement )
9498{
9599 CClientIFP & IFP = static_cast < CClientIFP& > ( *pElement );
96100 const unsigned int u32BlockNameHash = IFP.GetBlockNameHash ( );
97- std::shared_ptr < CClientIFP > pIFP = g_pClientGame->GetIFPPointerFromMap ( u32BlockNameHash );
98- if ( pIFP )
99- {
100- // Remove IFP from map, so we can indicate that it does not exist
101- g_pClientGame->RemoveIFPPointerFromMap ( u32BlockNameHash );
102-
103- // Remove IFP animations from replaced animations of peds/players
104- g_pClientGame->OnClientIFPUnload ( pIFP );
105- }
101+ for ( auto it = m_vecIFPElements.begin ( ); it != m_vecIFPElements.end ( ); ++it )
102+ {
103+ if ( (*it)->GetBlockNameHash ( ) == u32BlockNameHash )
104+ {
105+ m_vecIFPElements.erase ( it );
106+ break ;
107+ }
108+ }
106109}
107110
108111
@@ -130,6 +133,38 @@ void CElementDeleter::DoDeleteAll ( void )
130133}
131134
132135
136+ bool CElementDeleter::OnClientSpecialElementDestroy ( CClientEntity* pElement )
137+ {
138+ if ( IS_IFP ( pElement ) )
139+ {
140+ OnClientIFPElementDestroy ( pElement );
141+ return true ;
142+ }
143+ return false ;
144+ }
145+
146+
147+ void CElementDeleter::OnClientIFPElementDestroy ( CClientEntity * pElement )
148+ {
149+ CClientIFP & IFP = static_cast < CClientIFP& > ( *pElement );
150+ const unsigned int u32BlockNameHash = IFP.GetBlockNameHash ( );
151+
152+ std::shared_ptr < CClientIFP > pIFP = g_pClientGame->GetIFPPointerFromMap ( u32BlockNameHash );
153+ if ( pIFP )
154+ {
155+ // Remove IFP from map, so we can indicate that it does not exist
156+ g_pClientGame->RemoveIFPPointerFromMap ( u32BlockNameHash );
157+
158+ // Remove IFP animations from replaced animations of peds/players
159+ g_pClientGame->OnClientIFPUnload ( pIFP );
160+
161+ // keep a reference to shared_ptr CClientIFP in list, so it does not get
162+ // destroyed after exiting this function
163+ m_vecIFPElements.push_back ( pIFP );
164+ }
165+ }
166+
167+
133168bool CElementDeleter::IsBeingDeleted ( CClientEntity* pElement )
134169{
135170 return m_List.Contains ( pElement );
0 commit comments