Crash with memcpy
#1

Hey, I'm using this script (a modified version of ******'s quicksort) to sort arrays and copy the associated elements with it.

The server always seems to crash at the first call to memcpy in the code, but only when the gamemode is in a certain state (otherwise the method is working fine?).

I can't put my finger on why. Is this a bug or something I'm doing wrong? I get a consistent crash address when it crashes:

Код:
--------------------------

SA-MP Server: 0.3c R2



Exception At Address: 0x004A3DC3



Registers:

EAX: 0x00000080	EBX: 0xC984A338	ECX: 0x00000020	EDX: 0x00000000

ESI: 0x00000000	EDI: 0x0374C3D8	EBP: 0x0018F6BC	ESP: 0x0018F6B4

EFLAGS: 0x00010216



Stack:

+0000: 0x0374C3D8   0x021A1F00   0x035487E8   0x0040733B

+0010: 0x0374C3D8   0x00000000   0x00000080   0x021A1F00

+0020: 0xC984A338   0x0018F6FC   0x021A1F00   0x0015C584

+0030: 0x0018F6F0   0x021A1F00   0x035EFE54   0x0374C3D8

+0040: 0x00402C20   0x021A1F00   0x00000000   0x0018FBB0

+0050: 0x00000000   0x0374C59C   0x021A1F00   0xC984A338

+0060: 0x0015C590   0x0015C514   0x0015C73C   0x0014C75C

+0070: 0x0015C534   0x0014C75C   0x03542FA0   0x035EFE54

+0080: 0x00000000   0x03540020   0x000ACEB4   0x004879BE

+0090: 0x021A1F00   0x0018FBA0   0x0000004F   0x00480064

+00A0: 0x65727453   0x72656D61   0x506E4F5F   0x6579616C

+00B0: 0x746E4572   0x61527265   0x50436563   0x00487700

+00C0: 0x021A1F00   0x035EFE54   0x00000001   0x00000000

+00D0: 0x00000000   0x00000000   0x00000000   0x00000000

+00E0: 0x00000000   0x00000000   0x00000000   0x00000000

+00F0: 0x00000000   0x00000000   0x00000000   0x00000000

+0100: 0x00000000   0x00000000   0x00000000   0x004A6FE4

+0110: 0x004C2238   0xFFFFFFFF   0x004A2B5B   0x004A2B78

+0120: 0x00000006   0x004A483C   0x00000006   0x00000001

+0130: 0x00468AF1   0x00000006   0x0018F880   0x0020C438



--------------------------

SA-MP Server: 0.3c R2



Exception At Address: 0x004A3DC3



Registers:

EAX: 0x00000080	EBX: 0xC9829794	ECX: 0x00000020	EDX: 0x00000000

ESI: 0x00000000	EDI: 0x0391C3D4	EBP: 0x0018F6BC	ESP: 0x0018F6B4

EFLAGS: 0x00010216



Stack:

+0000: 0x0391C3D4   0x02161F00   0x037187E8   0x0040733B

+0010: 0x0391C3D4   0x00000000   0x00000080   0x02161F00

+0020: 0xC9829794   0x0018F6FC   0x02161F00   0x0015C580

+0030: 0x0018F6F0   0x02161F00   0x037BFE54   0x0391C3D4

+0040: 0x00402C20   0x02161F00   0x00000000   0x0018FBB0

+0050: 0x00000000   0x0391C59C   0x02161F00   0xC9829794

+0060: 0x0015C58C   0x0015C510   0x0015C73C   0x0014C75C

+0070: 0x0015C530   0x0014C75C   0x03712FA0   0x037BFE54

+0080: 0x00000000   0x03710020   0x000ACEB4   0x004879BE

+0090: 0x02161F00   0x0018FBA0   0x0000004F   0x00480064

+00A0: 0x65727453   0x72656D61   0x506E4F5F   0x6579616C

+00B0: 0x746E4572   0x61527265   0x50436563   0x00487700

+00C0: 0x02161F00   0x037BFE54   0x00000001   0x00000000

+00D0: 0x00000000   0x00000000   0x00000000   0x00000000

+00E0: 0x00000000   0x00000000   0x00000000   0x00000000

+00F0: 0x00000000   0x00000000   0x00000000   0x00000000

+0100: 0x00000000   0x00000000   0x00000000   0x004A6FE4

+0110: 0x0018F7B4   0xFFFFFFFF   0x0018F9BC   0x004A6FE4

+0120: 0x004C2238   0xFFFFFFFF   0x004A2B5B   0x004A2B78

+0130: 0x00000008   0x004A483C   0x00000008   0x00000001
Thanks for any assistance.
Reply
#2

No problem. I use this macro:

Код:
// QuickSortAssoc(array, sort_index, size, pivot_array)
#define QuickSortAssoc(%1,%2,%3,%4) \
	QSortAssoc((%1), _:(%2), 0, (%3) - 1, (%4), (%3))
Then when I call the code, this I what I'm using at the moment.

Код:
stock Race::UpdateScores() {
	enum
		eLinkedRaceScore {
			IPlayerID,
			Float:
				FRaceScore
	};
	
	new
		iCounter,
		aScores	[IMaxRacers][eLinkedRaceScore],
		aPivot	[eLinkedRaceScore];
	
	print("Before foreach");
	// Racer foreach will need to be implemented, you could do:
	//	foreach(Player, i) if(!IsPlayerInRace(i)) continue;
	foreach(Racer, i) {
		aScores[iCounter][eLinkedRaceScore:IPlayerID]	= i;
		aScores[iCounter][eLinkedRaceScore:FRaceScore]	= Race::GetRaceScore(i);
		
		printf("Racer (%d):", i);
		printf("iCounter = %d\r\nScore = %f", iCounter, aScores[iCounter][eLinkedRaceScore:FRaceScore]);
		
		iCounter++;
	}
	
	print("QuickSortAssoc (before)");
	QuickSortAssoc(aScores, FRaceScore, sizeof(aScores), aPivot);
	print("QuickSortAssoc (after)");
	new
		szString[128];
	
	printf("sizeof(aScores) = %d; iCounter = %d", sizeof(aScores), iCounter);
	printf("sizeof(aScores) - iCounter - 1 = %d", sizeof(aScores) - iCounter - 1);
	
	new
		iWinningPlayer = aScores[sizeof(aScores) - iCounter - 1][eLinkedRaceScore:IPlayerID];
	
	printf("iWinningPlayer = %d", iWinningPlayer);
	
	format(szString, sizeof(szString), "%s is coming first!", Player::GetName(iWinningPlayer));
	SendClientMessageToAll(0xFFFFFFFF, szString);
}
When the server crashes, the output before the crash is like so:

Код:
[01:34:53] Before foreach
[01:34:53] Racer (0):
[01:34:53] iCounter = 0

Score = -970016.500000
[01:34:53] QuickSortAssoc (before)
Reply
#3

Good observation skills! Thank you very much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)