Page 1 of 1

While

Posted: 2011 Nov 25 15:10
by KamiN
Ar gali dėl kurio nors iš šitų while susidaryti tas "amžinas ciklas"?

1

Code: Select all

while((pos <= sizeof(g_Buttons)) && (ent[0] = engfunc(EngFunc_FindEntityByString, ent[0], "classname", "info_player_deathmatch"))){pev(ent[0], pev_origin, origin)while((ent[1] = engfunc(EngFunc_FindEntityInSphere, ent[1], origin, CELL_RADIUS))){    if(!is_valid_ent(ent[1]))        continue            entity_get_string(ent[1], EV_SZ_classname, info, charsmax(info))    if(!equal(info, "func_door"))            continue                entity_get_string(ent[1], EV_SZ_targetname, info, charsmax(info))    if(!info[0])            continue                if(TrieKeyExists(g_CellManagers, info))            {                TrieGetCell(g_CellManagers, info, ent[2])            }        else            {                ent[2] = engfunc(EngFunc_FindEntityByString, 0, "target", info)            }                if(is_valid_ent(ent[2]) && (in_array(ent[2], g_Buttons, sizeof(g_Buttons)) < 0))            {                g_Buttons[pos] = ent[2]                pos++                break            }        }    }TrieDestroy(g_CellManagers)}
2

Code: Select all

      while ( gNum < MAX_MAPS && read_file("mapcycle.txt",line++,gMap,63,i) )    {        if ( gMap[0] == ';' ) continue         if (equali(gMap,map))        {            cyclerfile = true            break        }        ++gNum    } return PLUGIN_CONTINUE
3

Code: Select all

    while (nServerCount < g_nServerCount)    {        format(sFullAddress, MAX_SERVERADDRESS_LEN - 1, "%s:%d", g_saServerAddresses[nServerCount], g_naServerPorts[nServerCount])        if (equal(sFullAddress, sTmpOwnAddress) || equal(sFullAddress, sTmpServerIP))        {            g_nOwnServer = nServerCount            break        }        nServerCount++    }
---

4

Code: Select all

    while(engfunc(EngFunc_PointContents, vOrigin) == CONTENTS_EMPTY)        vOrigin[2] += 5.0;
5

Code: Select all

while (div > result)            // end when div == result, or just below    {        div = (div + result) / 2;    // take mean value as new divisor        result = num / div;    }
6

Code: Select all

while ((iWPNidx = find_ent_by_class(iWPNidx, wpn)) != 0)            {                if (id == entity_get_edict(iWPNidx, EV_ENT_owner))                {                    cs_set_weapon_ammo(iWPNidx, getMaxClipAmmo(wpnid));                    break;                }            }
7

Code: Select all

    while( (line = read_file(zonefile , line , input , 127 , len) ) != 0 )    {        if (!strlen(input)  || (input[0] == ';')) continue;    // Kommentar oder Leerzeile         new data[20], zm = 0, ct        // "abgebrochenen" Daten - ZoneMode - CamperTime        new Float:mins[3], Float:maxs[3], Float:pos[3]    // Gro?e & Position         // Zone abrufen        strbreak(input, data, 20, input, 999)        zm = -1        for(new i = 0; ZONEMODE:i < ZONEMODE; ZONEMODE:i++)        {            // Anderungen von CS:CZ zu allen Mods            if (equal(data, "wgz_camper_te")) format(data, 19, "wgz_camper_t1")            if (equal(data, "wgz_camper_ct")) format(data, 19, "wgz_camper_t2")            if (equal(data, zonename[ZONEMODE:i])) zm = i;        }                if (zm == -1)        {            log_amx("undefined zone -> '%s' ... dropped", data)            continue;        }                // Position holen        strbreak(input, data, 20, input, 999);    pos[0] = str_to_float(data);        strbreak(input, data, 20, input, 999);    pos[1] = str_to_float(data);        strbreak(input, data, 20, input, 999);    pos[2] = str_to_float(data);                // Dimensionen        strbreak(input, data, 20, input, 999);    mins[0] = str_to_float(data);        strbreak(input, data, 20, input, 999);    mins[1] = str_to_float(data);        strbreak(input, data, 20, input, 999);    mins[2] = str_to_float(data);        strbreak(input, data, 20, input, 999);    maxs[0] = str_to_float(data);        strbreak(input, data, 20, input, 999);    maxs[1] = str_to_float(data);        strbreak(input, data, 20, input, 999);    maxs[2] = str_to_float(data);         if ((ZONEMODE:zm == ZM_CAMPING) || (ZONEMODE:zm == ZM_CAMPING_T1) || (ZONEMODE:zm == ZM_CAMPING_T2))        {            // Campertime wird immer mitgeliefert            strbreak(input, data, 20, input, 999)            ct = str_to_num(data)        }         // und nun noch erstellen        CreateZone(pos, mins, maxs, zm, ct);    }

Re: While

Posted: 2011 Nov 25 17:15
by aaarnas
Visko gali būti. Paprasčiausia tai patikrinti praktiškai ir nekils abejonių.
Tokį bajerį padaryk grynai debuginimui:

Code: Select all

new ciklas = 0while(/*Kažkokia sąlyga*/) { /* Kažkoks kodas */ if (++ciklas > 10000) {log_to_file("amzinas_ciklas.log", "Pluginas tatata.amxx eilute 555 susidare amzinas ciklas.")break;}}
Su šiuo būdu ne tik rasi kur susidaro amžinas ciklas, bet ir jį sustabdysi, jei netyčia atsirastų jis. Dėl to gali kilti kokių nors plugino klaidų, bet bent jau serveris neužlūš.

Šitą įdedi į tą while ciklą, kurį nori patikrinti. Aišku ten prie log parašyk visus duomenis, kad po to norint rasti, galėtum surasti kuris ciklas pastrigo.

Ir stebėk po to log aplanką. Jei buvo pastrigę, tai atsiras amzinas_ciklas.log failas ir ten bus parašyta kur, kas ir kada. O jau tada galima ieškoti problemos.

Re: While

Posted: 2011 Nov 25 17:55
by KamiN

Code: Select all

    while ((iWPNidx = find_ent_by_class(iWPNidx, wpn)) != 0)                {                    if (id == entity_get_edict(iWPNidx, EV_ENT_owner))                    {                        cs_set_weapon_ammo(iWPNidx, getMaxClipAmmo(wpnid));                        break;                    }                    if (ciklas > 10000)                     {                        log_to_file("amzinas_ciklas.log", "Pluginas tatata.amxx eilute 555 susidare amzinas ciklas.")                        break;                    }                }
Va taip pvz?

Re: While

Posted: 2011 Nov 25 18:02
by hleV
ciklas -> ++ciklas

Re: While

Posted: 2011 Nov 25 19:38
by aaarnas
hleV wrote:ciklas -> ++ciklas
Dėkui. Pamiršau.