@@ -35,6 +35,8 @@ void CElementDeleter::Delete ( class CClientEntity* pElement )
35
35
// Add it to our list
36
36
if ( !pElement->IsBeingDeleted () )
37
37
{
38
+ // Just to be clear, not a Lua event
39
+ OnClientSpecialElementDestroy ( pElement );
38
40
m_List.push_back ( pElement );
39
41
}
40
42
@@ -68,6 +70,8 @@ void CElementDeleter::DeleteRecursive ( class CClientEntity* pElement )
68
70
// Add it to our list over deleting objects
69
71
if ( !pElement->IsBeingDeleted () )
70
72
{
73
+ // Just to be clear, not a Lua event
74
+ OnClientSpecialElementDestroy ( pElement );
71
75
m_List.push_back ( pElement );
72
76
}
73
77
@@ -94,15 +98,14 @@ void CElementDeleter::DeleteIFP ( CClientEntity * pElement )
94
98
{
95
99
CClientIFP & IFP = static_cast < CClientIFP& > ( *pElement );
96
100
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
+ }
106
109
}
107
110
108
111
@@ -130,6 +133,38 @@ void CElementDeleter::DoDeleteAll ( void )
130
133
}
131
134
132
135
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
+
133
168
bool CElementDeleter::IsBeingDeleted ( CClientEntity* pElement )
134
169
{
135
170
return m_List.Contains ( pElement );
0 commit comments