Bug: +INVENTORY.AUTOACTIVATE items with MaxAmount != 0...

Sun Oct 21, 2018 9:31 am

...may not activate in a certain case.

When two identical items with +INVENTORY.AUTOACTIVATE and Inventory.MaxAmount > 0 are spawned at the exact same location, only one item will actually auto-activate. The other item will just disappear and be wasted. However, it doesn't happen if MaxAmount is set to 0.

The reason for this is that there is special logic which handles auto-activation of items with MaxAmount == 0, but if the latter is not the case, then normal logic is used, which calls HandlePickup to see if any item in the player's inventory can handle the pickup, and that's where auto-activation will fail.

So, if the item class has MaxAmount == 0, then the third branch of TryPickup will execute for both items and none of the items will go to the player's inventory. However, if MaxAmount > 0, then the second branch will execute for the first item. The item will be added to the player's inventory, where its auto-activation flag will be checked and processed. However, the item will not disappear from the player's inventory for long enough so that picking up the next item will trigger the first branch because CallHandlePickup will return true. Since neither HandlePickup nor TryPickup process auto-activation in this case, the second item will simply disappear without doing anything useful.

Attached to this post is an example to demonstrate this behavior. Go to any map, open the console and type "summon TestInv" two times. Each TestInv is supposed to give the player one health point, but you will only get one. Note that spawning more than two items will usually give more health points than one, but always less than they were actually supposed to give. Now edit the example and uncomment "Inventory.MaxAmount 0", then repeat the testing procedure. You will now correctly get two health points for two spawned items.

Tested in: GZDoom 3.6.0, g3.7pre-9-g4ac43dac3
You do not have the required permissions to view the files attached to this post.

Re: Bug: +INVENTORY.AUTOACTIVATE items with MaxAmount != 0..

Sun Oct 21, 2018 8:57 pm

I talked about this bug 3 years ago. viewtopic.php?f=7&t=48305

Re: Bug: +INVENTORY.AUTOACTIVATE items with MaxAmount != 0..

Sun Oct 21, 2018 10:23 pm

That one was closed, so I am going to leave this one open. Hopefully any further samples that may be needed will be a little more forthcoming this time around.

Re: Bug: +INVENTORY.AUTOACTIVATE items with MaxAmount != 0..

Mon Oct 22, 2018 12:18 am

Rowsol wrote:I talked about this bug 3 years ago. viewtopic.php?f=7&t=48305



So why didn't you give the requested feedback back then? I specifically asked for it and nothing happened for 7 months. No wonder it didn't get fixed.
The cause is very obvious based on the presented evidence here: Any item in the inventory which has been set to its 'HoldAndDestroy' state may not handle any other item given to it. But without anything to test I had to close the older report.

Re: Bug: +INVENTORY.AUTOACTIVATE items with MaxAmount != 0..

Mon Oct 22, 2018 10:34 am

I just found it interesting that it took 3.5 years for someone else to mention it. Glad you figured it out.