﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
2161	DllStructs Corrupted When Returned In Array.	anonymous		"When returning an array of DllStructs, they will sometimes be corrupted. I was using the following to rapidly pull data from a program. All of the data is perfect within the function itself, however the data will often be corrupted once returned (to be used elsewhere).

{{{
Func GetAgentArray($aType = 0)
	DllStructSetData($mMakeAgentArray, 2, $aType)
	MemoryWrite($mAgentCopyCount, -1, 'long')
	Enqueue($mMakeAgentArrayPtr, 8)
	Local $lDeadlock = TimerInit()
	Local $lCount = MemoryRead($mAgentCopyCount, 'long')
	While $lCount == -1 And TimerDiff($lDeadlock) < 5000
		Sleep(1)
		$lCount = MemoryRead($mAgentCopyCount, 'long')
	WEnd
;~ 	Above this line isn't directly related to bug
	Local $lBuffer = DllStructCreate('Byte[' & 448 * $lCount & ']')
	DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $mAgentCopyBase, 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
	Local $lReturnArray[$lCount + 1] = [$lCount]
	Local $lStructPtr = DllStructGetPtr($lBuffer)
	For $i = 1 To $lCount
		$lReturnArray[$i] = DllStructCreate('ptr vtable;byte unknown1[24];byte unknown2[4];ptr NextAgent;byte unknown3[8];long Id;float Z;byte unknown4[8];float BoxHoverWidth;float BoxHoverHeight;byte unknown5[8];float Rotation;byte unknown6[8];long NameProperties;byte unknown7[24];float X;float Y;byte unknown8[8];float NameTagX;float NameTagY;float NameTagZ;byte unknown9[12];long Type;float MoveX;float MoveY;byte unknown10[28];long Owner;byte unknown30[8];long ExtraType;byte unknown11[24];float AttackSpeed;float AttackSpeedModifier;word PlayerNumber;byte unknown12[6];ptr Equip;byte unknown13[10];byte Primary;byte Secondary;byte Level;byte Team;byte unknown14[6];float EnergyPips;byte unknown[4];float EnergyPercent;long MaxEnergy;byte unknown15[4];float HPPips;byte unknown16[4];float HP;long MaxHP;long Effects;byte unknown17[4];byte Hex;byte unknown18[18];long ModelState;long TypeMap;byte unknown19[16];long InSpiritRange;byte unknown20[16];long LoginNumber;float ModelMode;byte unknown21[4];long ModelAnimation;byte unknown22[32];byte LastStrike;byte Allegiance;word WeaponType;word Skill;byte unknown23[4];word WeaponItemId;word OffhandItemId', $lStructPtr)
		$lStructPtr += 448
;~ 		Data is perfect when written to console here.
	Next
	Return $lReturnArray
EndFunc   ;==>GetAgentArray
}}}

But when called with the following, it will give me lots of bad information. If I don't set $arr to 0 (like I do in the following), it will (usually) stop causing issues after a few calls. (Probably a memory allocation issue.)


{{{
While 1
	Local $arr = Getagentarray(0x400)
	If $arr[0] = 0 Then ContinueLoop
	out(DllStructGetData($arr[1], 'X')) ;Data is very often incorrect.
	$arr = 0
	Sleep(20)
WEnd
}}}"	Bug	closed		AutoIt	3.3.8.0	None	No Bug	DllStruct	
