Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie

Przerabiane statsx problem (logi)


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
2 odpowiedzi w tym temacie

#1 sebo97

    Zaawansowany

  • Użytkownik

Reputacja: -1
Nowy

  • Postów:75
  • Lokalizacja:Łomża
Offline

Napisano 11.02.2014 20:15

Witam mam plugin statsx z tym nowym wyglądałem który sobie trochę przerobiłem (min. na top10) i mam takie erroy, które powodują crashe, co to może być i jak to naprawić?
 
L 02/10/2014 - 19:47:20: [AMXX] Displaying debug trace (plugin "statsx.amxx")
L 02/10/2014 - 19:47:20: [AMXX] Run time error 10: native error (native "replace")
L 02/10/2014 - 19:47:20: [AMXX]    [0] statsx.sma::client_color (line 262)
L 02/10/2014 - 19:47:20: [AMXX]    [1] statsx.sma::cmdHp (line 1050)
 
linijka 262:
while(replace(msg,127,"!W","^x01")){}
linijka 1050:
client_color( id, g_sBuffer)

 


Użytkownik Benio101 edytował ten post 11.02.2014 20:31
Dodanie znacznika CODE

  • +
  • -
  • 0

#2 Gość_21977_*

  • Gość

Reputacja: 0

Offline

Napisano 11.02.2014 20:53

string.cpp

static cell AMX_NATIVE_CALL replace(AMX *amx, cell *params) /* 4 param */
{
	cell *text = get_amxaddr(amx, params[1]);
	cell len = params[2];
	cell *what = get_amxaddr(amx, params[3]);
	cell *with = get_amxaddr(amx, params[4]);
	cell *textptr = text;

	int withLen = amxstring_len(with);
	int whatLen = amxstring_len(what);
	int textLen = amxstring_len(text);

	if (whatLen > textLen)
		return 0;

	if (whatLen < 1)
	{
		LogError(amx, AMX_ERR_NATIVE, "No search string specified.");
		return 0;
	}

	if (textLen - whatLen + withLen > len)
	{
		LogError(amx, AMX_ERR_NATIVE, "replace() buffer not big enough (%d>=%d)", (textLen - whatLen + withLen), len);
		return 0;
	}

	cell browsed = 0;
	while (*text && (browsed <= (textLen-whatLen)))
	{
		if (*text == *what)
		{
			if (fastcellcmp(text, what, whatLen))
			{
				cell *saveptr = text + whatLen;
				cell restlen = textLen - (browsed + whatLen);
				textptr = text + withLen;
				memmove(textptr, saveptr, (restlen + 1) * sizeof(cell));
				memcpy(text, with, withLen * sizeof(cell));
				return (textLen - whatLen + withLen);
			}
		}
		text++;
		browsed++;
	}
	
	return 0;
}

Przyjrzyj się funkcji i zastanów, dlaczego błąd występuje.

btw. Istnieje stock replace_all, który w tym wypadku wydaje się być lepszym rozwiązaniem.

 

string.inc

/* Replaces a contained string iteratively.
 * This ensures that no infinite replacements will take place by
 *  intelligently moving to the next string position each iteration.
 */
stock replace_all(string[], len, const what[], const with[])
{
	new pos = 0;
	
	if ((pos = contain(string, what)) == -1)
	{
		return 0;
	}
	
	new total = 0;
	new with_len = strlen(with);
	new diff = strlen(what) - with_len;
	new total_len = strlen(string);
	new temp_pos = 0;
	
	while (replace(string[pos], len - pos, what, with) != 0)
	{
		total++;
 
		/* jump to position after replacement */
		pos += with_len;
		
		/* update cached length of string */
		total_len -= diff;
		
		/* will the next call be operating on the last character? */
		if (pos >= total_len)
		{
			break;
		}
		
		/* find the next position from our offset */
		temp_pos = contain(string[pos], what);
		
		/* if it's invalid, we're done */
		if (temp_pos == -1)
		{
			break;
		}
		
		/* otherwise, reposition and update counters */
		pos += temp_pos;
	}
	
	return total;
}


#3 sebo97

    Zaawansowany

  • Autor tematu
  • Użytkownik

Reputacja: -1
Nowy

  • Postów:75
  • Lokalizacja:Łomża
Offline

Napisano 12.02.2014 15:38

To wystarczy czy zamienię
replace
na
replace_all
??
  • +
  • -
  • 0




Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych