Veteran Member
07-22-2021
, 13:37
Memory leakage caused by not destroying menu properly
#1
Error log :-
Code :-
Spoiler
PHP Code:
enum any : Hudmessages_Params (+= 1 )
{
HUDMSG_STRING [ HUDMESSAGE_MAX_LEN ] = 0 ,
HUDMSG_COLOR_R ,
HUDMSG_COLOR_G ,
HUDMSG_COLOR_B ,
Float : HUDMSG_POS_X ,
Float : HUDMSG_POS_Y ,
HUDMSG_EFFECTS ,
Float : HUDMSG_FXTIME ,
Float : HUDMSG_HOLDTIME ,
Float : HUDMSG_FADEIN_TIME ,
Float : HUDMSG_FADEOUT_TIME ,
HUDMSG_REPEAT ,
HUDMSG_STYLE ,
HUDMSG_ID [ 32 ],
HUDMSG_RECEIVER [ 32 ],
HUDMSG_DATA_PARAMS_ARRAY
}
enum any : Hudmessage_SetTask_Data (+= 1 )
{
HUDMSG_DATA_USERS [ 32 ],
HUDMSG_DATA_MAXUSERS ,
HUDMSG_DATA_ARRAY_INDEX ,
HUDMSG_DATA_ARRAY_ITEM ,
HUDMSG_DATA_TARGET ,
HUDMSG_DATA_TASK_INDEX
}
...............
if( _ : xArray [ HUDMESSAGES_ARRAY ] > - 1 ) // valid hudmessage array handler :)
{
target = team = - 1 ;
iCurTaskID = 0 ;
xArray2 [ HUDMSG_REPEAT ] = 0 ;
ArrayGetArray ( xArray [ HUDMESSAGES_ARRAY ], random ( ArraySize ( xArray [ HUDMESSAGES_ARRAY ])), xArray2 )
replace_string_args ( xArray2 [ HUDMSG_RECEIVER ], charsmax ( xArray2 [ HUDMSG_RECEIVER ]), iUsers , g_maxusers );
switch( xArray2 [ HUDMSG_RECEIVER ][ 0 ] )
{
case EOS : target = team = 0 ;
case '~' : { target = find_player ( "b" , xArray2 [ HUDMSG_RECEIVER ][ 1 ]); target = ! target ? - 1 : target ; team = 0 ; }
case '#' : { target = find_player ( "k" , str_to_num ( xArray2 [ HUDMSG_RECEIVER ][ 1 ])); target = ! target ? - 1 : target ; team = 0 ; }
case '@' :
{
target = 0 ;
switch( xArray2 [ HUDMSG_RECEIVER ][ 1 ] )
{
case 'C' , 'c' , 'G' , 'g' : team = 'C' ;
case 'T' , 't' , 'P' , 'p' : team = 'T' ;
case 's' , 'S' : team = 'S' ;
default: team = - 1 ;
}
}
default:
{
team = 0 ;
target = find_player ( "a" , xArray2 [ HUDMSG_RECEIVER ]); // search for player by fullname
if(! target ) target = find_player ( "c" , xArray2 [ HUDMSG_RECEIVER ]); // search for player by steamid
if(! target ) target = find_player ( "d" , xArray2 [ HUDMSG_RECEIVER ]); // search for player by ip
if(! target ) target = - 1 ;
}
}
if( target != - 1 && team != - 1 )
{
copy ( szMessage , charsmax ( szMessage ), xArray2 [ HUDMSG_STRING ]);
z = x = n = 0 ;
while( strfind ( szMessage , "#%value(" ) != - 1 )
{
if( n > iLen || ( n = strfind ( msglog , "'" , _ , n )) == - 1 ) break;
n ++;
if( strfind ( msglog [ n ], "'" ) == - 1 ) break;
z ++;
n += copyc ( szExtLog , charsmax ( szExtLog ), msglog [ n ], '''' );
n ++;
formatex ( szString , charsmax ( szString ), "#%%value(%d)" , z );
if( containi ( szMessage , szString ) > - 1 )
{
replace_all ( szMessage , charsmax ( szMessage ), szString , szExtLog );
if( xArray2 [ HUDMSG_REPEAT ] > 0 ) replace_all ( xArray2 [ HUDMSG_STRING ], charsmax ( xArray2 [ HUDMSG_STRING ]), szString , szExtLog );
}
}
replace_string_args ( szMessage , charsmax ( szMessage ), iUsers , g_maxusers );
static players [ 32 ], pnum ;
switch( team )
{
case 'C' : get_players ( players , pnum , "che" , "CT" );
case 'T' : get_players ( players , pnum , "che" , "TERRORIST" );
case 'S' : get_players ( players , pnum , "che" , "SPECTATOR" );
default: players [ ( pnum = 1 ) - 1 ] = target ;
}
x = pnum ;
switch( xArray2 [ HUDMSG_STYLE ] )
{
case 0 :
{
set_hudmessage ( xArray2 [ HUDMSG_COLOR_R ], xArray2 [ HUDMSG_COLOR_G ], xArray2 [ HUDMSG_COLOR_B ], xArray2 [ HUDMSG_POS_X ],
xArray2 [ HUDMSG_POS_Y ], xArray2 [ HUDMSG_EFFECTS ], xArray2 [ HUDMSG_FXTIME ], xArray2 [ HUDMSG_HOLDTIME ],
xArray2 [ HUDMSG_FADEIN_TIME ], xArray2 [ HUDMSG_FADEOUT_TIME ], - 1 );
while( pnum -- > 0 )
{
show_hudmessage ( players [ pnum ], szMessage );
}
}
case 1 :
{
set_dhudmessage ( xArray2 [ HUDMSG_COLOR_R ], xArray2 [ HUDMSG_COLOR_G ], xArray2 [ HUDMSG_COLOR_B ], xArray2 [ HUDMSG_POS_X ],
xArray2 [ HUDMSG_POS_Y ], xArray2 [ HUDMSG_EFFECTS ], xArray2 [ HUDMSG_FXTIME ], xArray2 [ HUDMSG_HOLDTIME ],
xArray2 [ HUDMSG_FADEIN_TIME ], xArray2 [ HUDMSG_FADEOUT_TIME ]);
while( pnum -- > 0 )
{
show_dhudmessage ( players [ pnum ], szMessage );
}
}
}
pnum = x ;
if(( z = xArray2 [ HUDMSG_REPEAT ]) >= 1 ) // repeats
{
new Array: iTempArray = any :- 1 , iTempArrayItem ;
if( xArray2 [ HUDMSG_ID ][ 0 ] != EOS ) // if hudmessage has a taskid to be able to terminate it
{
if(! TrieKeyExists ( Trie_Hudmessages_ids , xArray2 [ HUDMSG_ID ]))
TrieSetCell ( Trie_Hudmessages_ids , xArray2 [ HUDMSG_ID ], ( iCurTaskID = g_TaskIDs ));
else
TrieGetCell ( Trie_Hudmessages_ids , xArray2 [ HUDMSG_ID ], iCurTaskID );
if(( target > 0 || team > 0 ) && pnum > 0 )
{
x = pnum ;
while( pnum -- > 0 )
{
n = players [ pnum ];
formatex ( szHUDID , charsmax ( szHUDID ), "%s_#%d" , xArray2 [ HUDMSG_ID ], get_user_userid ( n ));
TrieSetCell ( Trie_Hudmessages_ids , szHUDID , ( iCurTaskID + n ));
}
pnum = x ;
}
g_TaskIDs += 35 ; // GLOBAL VARIABLE
x = ArraySize ( g_ArrayRepeatingData );
while ( x -- > 0 )
{
ArrayGetArray ( g_ArrayRepeatingData , x , xArray3 );
if( equal ( xArray3 [ HUDMSG_ID ], xArray2 [ HUDMSG_ID ])) // Seeking if the current TASKID already on repeat inside g_ArrayRepeatingData Array
{
iTempArray = any : xArray3 [ HUDMSG_DATA_PARAMS_ARRAY ];
iTempArrayItem = ArraySize ( iTempArray );
break;
}
}
}
g_aHUDMSG_DATA [ HUDMSG_DATA_ARRAY_INDEX ] = _ : g_ArrayRepeatingData ;
g_aHUDMSG_DATA [ HUDMSG_DATA_TASK_INDEX ] = iCurTaskID ;
for( x = 0 , n = sizeof iUsers ; x < n ; x ++)
{
g_aHUDMSG_DATA [ HUDMSG_DATA_USERS ][ x ] = iUsers [ x ];
}
g_aHUDMSG_DATA [ HUDMSG_DATA_MAXUSERS ] = g_maxusers ;
if( iTempArray == any :- 1 )
{
iTempArray = ArrayCreate ( Hudmessage_SetTask_Data , 1 );
}
xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ] = any : iTempArray ;
while( pnum -- > 0 )
{
f = players [ pnum ];
g_aHUDMSG_DATA [ HUDMSG_DATA_TARGET ] = ! f ? 0 : get_user_userid ( f );
g_aHUDMSG_DATA [ HUDMSG_DATA_ARRAY_ITEM ] = ArraySize ( g_ArrayRepeatingData );
ArrayPushArray ( g_ArrayRepeatingData , xArray2 );
ArrayPushArray ( iTempArray , g_aHUDMSG_DATA );
if( xArray2 [ HUDMSG_ID ][ 0 ] != EOS ) // Check if Hudmessage has an id if so remove the old task.
{
remove_task ( iCurTaskID + f );
}
// Show new task.
formatex ( szParams , charsmax ( szParams ), "%d %d" , iTempArray , iTempArrayItem ++);
set_task ( xArray2 [ HUDMSG_HOLDTIME ], "task_hudmessage_repeat" , iCurTaskID + f , szParams , sizeof szParams , z > 1 ? "a" : "b" , z );
}
}
}
}
}
}
}
public task_hudmessage_repeat (const params [], const taskid )
{
static index , target , szString [ 16 ], aHUDMSG_DATA [ Hudmessage_SetTask_Data ], iTempArray , iTempArrayItem ;
iTempArrayItem = str_to_num ( params [ copyc ( szString , charsmax ( szString ), params , ' ' ) ]);
iTempArray = any : str_to_num ( szString );
ArrayGetArray ( any : iTempArray , iTempArrayItem , aHUDMSG_DATA ); // Error line.
target = aHUDMSG_DATA [ HUDMSG_DATA_TARGET ];
index = find_player ( "k" , target );
static any : xArray2 [ Hudmessages_Params ], MaxUsers , ItemID , any : ArrayID , iUsers [ 32 ];
copy ( iUsers , charsmax ( iUsers ), aHUDMSG_DATA [ HUDMSG_DATA_USERS ]);
MaxUsers = aHUDMSG_DATA [ HUDMSG_DATA_MAXUSERS ];
ArrayID = aHUDMSG_DATA [ HUDMSG_DATA_ARRAY_INDEX ];
ItemID = aHUDMSG_DATA [ HUDMSG_DATA_ARRAY_ITEM ];
ArrayGetArray ( ArrayID , ItemID , xArray2 );
if( target > 0 && ! is_user_connected ( index ))
{
new szHUDID [ 32 ];
formatex ( szHUDID , charsmax ( szHUDID ), "%s_#%d" , xArray2 [ HUDMSG_ID ], target );
TrieDeleteKey ( Trie_Hudmessages_ids , szHUDID );
remove_task ( taskid );
return;
}
replace_string_args ( xArray2 [ HUDMSG_STRING ], charsmax ( xArray2 [ HUDMSG_STRING ]), iUsers , MaxUsers );
switch( xArray2 [ HUDMSG_STYLE ] )
{
case 0 :
{
set_hudmessage ( xArray2 [ HUDMSG_COLOR_R ], xArray2 [ HUDMSG_COLOR_G ], xArray2 [ HUDMSG_COLOR_B ], xArray2 [ HUDMSG_POS_X ],
xArray2 [ HUDMSG_POS_Y ], xArray2 [ HUDMSG_EFFECTS ], xArray2 [ HUDMSG_FXTIME ], xArray2 [ HUDMSG_HOLDTIME ],
xArray2 [ HUDMSG_FADEIN_TIME ], xArray2 [ HUDMSG_FADEOUT_TIME ], - 1 );
show_hudmessage ( index , "%s" , xArray2 [ HUDMSG_STRING ]);
}
case 1 :
{
set_dhudmessage ( xArray2 [ HUDMSG_COLOR_R ], xArray2 [ HUDMSG_COLOR_G ], xArray2 [ HUDMSG_COLOR_B ], xArray2 [ HUDMSG_POS_X ],
xArray2 [ HUDMSG_POS_Y ], xArray2 [ HUDMSG_EFFECTS ], xArray2 [ HUDMSG_FXTIME ], xArray2 [ HUDMSG_HOLDTIME ],
xArray2 [ HUDMSG_FADEIN_TIME ], xArray2 [ HUDMSG_FADEOUT_TIME ]);
show_dhudmessage ( index , "%s" , xArray2 [ HUDMSG_STRING ]);
}
}
// Removing the temporary repeat task from the run task list/trie
if( xArray2 [ HUDMSG_REPEAT ] > 1 )
{
xArray2 [ HUDMSG_REPEAT ]--;
ArraySetArray ( ArrayID , ItemID , xArray2 );
if( xArray2 [ HUDMSG_REPEAT ] <= 1 )
{
remove_hudtask ( xArray2 [ HUDMSG_ID ], ArrayID );
}
}
}
remove_hudtask (const szTaskid [], const Array: g_ArrayRepeatingData )
{
static xArray2 [ Hudmessages_Params ], aHUDMSG_DATA [ Hudmessage_SetTask_Data ], szHUDID [ 32 ], Array: iTempArray , x , z , f , n , i ;
iTempArray = any :- 1 ;
if( TrieKeyExists ( Trie_Hudmessages_ids , szTaskid )) {
TrieGetCell ( Trie_Hudmessages_ids , szTaskid , f );
remove_task ( f );
TrieDeleteKey ( Trie_Hudmessages_ids , szTaskid );
}
x = ArraySize ( g_ArrayRepeatingData );
while( x -- > 0 ) // backward looping
{
ArrayGetArray ( g_ArrayRepeatingData , x , xArray2 );
if( equal ( szTaskid , xArray2 [ HUDMSG_ID ]))
{
if( any : xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ] > - 1 )
{
n = ArraySize ( any : xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ]);
for( f = 0 ; f < n ; f ++)
{
ArrayGetArray ( any : xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ], f , aHUDMSG_DATA );
// Its a global hudmessage? just incase check !
if(! aHUDMSG_DATA [ HUDMSG_DATA_TARGET ]) continue;
formatex ( szHUDID , charsmax ( szHUDID ), "%s_#%d" , szTaskid , aHUDMSG_DATA [ HUDMSG_DATA_TARGET ]);
if(! TrieKeyExists ( Trie_Hudmessages_ids , szHUDID )) continue;
TrieGetCell ( Trie_Hudmessages_ids , szHUDID , z );
TrieDeleteKey ( Trie_Hudmessages_ids , szHUDID );
remove_task ( z );
}
// Get The Hudmsg SetTask Data Array so we can destroy it latter!
iTempArray = any : xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ];
}
ArrayDeleteItem ( g_ArrayRepeatingData , x );
i = x ;
z = ArraySize ( g_ArrayRepeatingData );
while( i < z )
{
ArrayGetArray ( g_ArrayRepeatingData , i , xArray2 );
n = ArraySize ( any : xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ]); // Getting the Hudmsg SetTask Array Index Size
for( f = 0 ; f < n ; f ++) // looping through the Array.
{
ArrayGetArray ( any : xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ], f , aHUDMSG_DATA );
if( g_aHUDMSG_DATA [ HUDMSG_DATA_ARRAY_ITEM ] > x ) // Checking if the g_ArrayRepeatingData Item id is bigger than the counter x
{
aHUDMSG_DATA [ HUDMSG_DATA_ARRAY_ITEM ]--; // decreasing item id by 1 grade.
ArraySetArray ( any : xArray2 [ HUDMSG_DATA_PARAMS_ARRAY ], f , aHUDMSG_DATA ); // Save back to the Hudmsg SetTask Array.
}
}
i ++;
}
}
}
if( iTempArray != any :- 1 ) ArrayDestroy ( iTempArray );
}
__________________
Last edited by Natsheh; 07-28-2021 at 08:42 .