22.11.2014, 05:31
This is not a bug..
It happens on any programming language. If you create a timer and then create another one and store the ID in the same variable, then it will be inaccessible, which is therefore called a memory leak because the first timer has no reference.
A fix is pretty simple: just use "-1" as an indication that the timer is not running.
It happens on any programming language. If you create a timer and then create another one and store the ID in the same variable, then it will be inaccessible, which is therefore called a memory leak because the first timer has no reference.
A fix is pretty simple: just use "-1" as an indication that the timer is not running.
pawn Код:
#define INVALID_TIMER_ID (-1)
new
g_iTimerID[MAX_PLAYERS]
;
public OnPlayerConnect(playerid) {
g_iTimerID[playerid] = INVALID_TIMER_ID;
}
public OnPlayerDisconnect(playerid, reason) {
if (g_iTimerID[playerid] != INVALID_TIMER_ID) {
KillTimer(g_iTimerID[playerid]);
}
}
CMD:timer(playerid, params[]) {
if (g_iTimerID[playerid] != INVALID_TIMER_ID)
KillTimer(g_iTimerID[playerid]);
else
g_iTimerID[playerid] = SetTimerEx("...", 1500, false, "d", playerid);
}