SA-MP Forums Archive
Incorrect string from AMX - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: Incorrect string from AMX (/showthread.php?tid=119723)



Incorrect string from AMX - izstas - 09.01.2010

For example, I call GetPlayerName.

Sometimes i got incorrect name (for example, dLASH48 instead of FLASH4 or... part of some chat message.

What's the problem?

Code:
	cell amxArgs[4];	
	cell *nameCellAddr;

	amxArgs[0] = 3 * sizeof(cell);
	amxArgs[1] = player;
	amx_Allot(AMX, MaxPlayerNameLength, amxArgs + 2, &nameCellAddr);
	amxArgs[3] = MaxPlayerNameLength;

	InvokeAMX(Native::GetPlayerName, amxArgs);

	char* name = new char[MaxPlayerNameLength];

	amx_GetString(name, nameCellAddr, 0, MaxPlayerNameLength);
	amx_Release(AMX, amxArgs[2]);

	return name;
InvokeAMX is defined and works fine...


Re: Incorrect string from AMX - Streetplaya - 09.01.2010

A sidenote, always make sure to deallocate memory you allocate.

new -> delete
new[] -> delete[]
malloc() -> free()