Quote:
Originally Posted by Emmet_
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.
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); }
|
What I said:
Quote:
It is a programming mistake; you can call it a bug, error, whatever; I call it a bug
|
Simplest explanation for newbies and new programmers. I created this topic because I saw many servers and programmers with this problem.
Thanks for feedback, +REP