Inventory/Weapon temporary loops in netplay

Discussions about Coding and Scripting
Buggie
Godlike
Posts: 1906
Joined: Sat Mar 21, 2020 5:32 am

Inventory/Weapon temporary loops in netplay

Post by Buggie »

I look in UT code and find interesting comments for Inventory loops in ChallengeHUD:

Code: Select all

	i = 0;
	for ( Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory )
	{
		if ( Inv.IsA('Weapon') && (Inv != PawnOwner.Weapon) )
		{
			W = Weapon(Inv);
			if ( WeaponSlot[W.InventoryGroup] == None )
				WeaponSlot[W.InventoryGroup] = W;
			else if ( (WeaponSlot[W.InventoryGroup] != PawnOwner.Weapon)
					&& ((W == PawnOwner.PendingWeapon) || (WeaponSlot[W.InventoryGroup].AutoSwitchPriority < W.AutoSwitchPriority)) )
				WeaponSlot[W.InventoryGroup] = W;
		}
		i++;
		if ( i > 100 )
			break; // can occasionally get temporary loops in netplay
	}
https://github.com/Slipyx/UT99/blob/a26 ... UD.uc#L746

Code: Select all

	ArmorAmount = 0;
	CurAbs = 0;
	i = 0;
	BestArmor=None;
	for( Inv=PawnOwner.Inventory; Inv!=None; Inv=Inv.Inventory )
	{ 
		if (Inv.bIsAnArmor) 
		{
			if ( Inv.IsA('UT_Shieldbelt') )
				bShieldbelt = true;
			else if ( Inv.IsA('Thighpads') )
			{
				ThighAmount += Inv.Charge;
				bThighArmor = true;
			}
			else
			{ 
				bChestArmor = true;
				ChestAmount += Inv.Charge;
			}
			ArmorAmount += Inv.Charge;
		}
		else if ( Inv.IsA('UT_JumpBoots') )
			bJumpBoots = true;
		else
		{
			i++;
			if ( i > 100 )
				break; // can occasionally get temporary loops in netplay
		}
	}
https://github.com/Slipyx/UT99/blob/a26 ... UD.uc#L437

I can confirm, this loops really happens. I can get it few times when want leave MH server and fast drop all my weapons to another player via ThrowWeapon key.

UT crash in my code in PostRender HUD, where exists loop:

Code: Select all

for( Inv=me.Inventory; Inv!=None; Inv=Inv.Inventory ) {
Also there another loop:

Code: Select all

ForEach me.AllActors(class'Weapon', weap) {
And I am not remember exactly, where crash happen.

In any case, if you have some loops which similar, better implement similar check for avoid UT crash on some cases.
User avatar
TheDane
Masterful
Posts: 657
Joined: Tue Feb 12, 2008 2:47 pm
Personal rank: Happy fool :-)

Re: Inventory/Weapon temporary loops in netplay

Post by TheDane »

This is why I never end my loops with the break command. I end my loops by 100% control over i, e.g. i=999;

This runaway looping only happened to me in loops where I called functions from within, just like the two examples you post.
Retired.