Repository navigation
Conversation
…#1617) CChar::OnRemoveObj fires @Unequip while the item is still equipped. If the trigger moved the same item again, the nested removal unequipped it completely, then the outer one did it a second time: the item bonuses were subtracted twice, the item was inserted twice in the new container (and its weight added twice) and CSObjCont::OnRemoveObj asserted on 'pObjRec->GetParent() == this'. The usual way to get there is a script lowering the STR in @Unequip: Stat_StrCheckEquip found the item still equipped and bounced it again. With script packs using @DropOn_Item, the bounce also reset the trigger recursion guard of the item, so @Unequip was fired again and again until the STR underflowed. - Mark the item while its @Unequip trigger runs: Stat_StrCheckEquip skips it and a nested removal doesn't fire @Unequip again. - If the trigger already moved or deleted the item, stop the outer removal in CChar::OnRemoveObj. - CSObjCont::InsertContentTail doesn't insert a record that the removal from its old container moved elsewhere, and CContainer::ContentAddPrivate reports it, so the weight isn't added twice and the callers don't place the item again.
|
Looks pretty excesive. How does it compare to this change: mtwango@eabc83c |
|
Glad you asked.
|
…phereserver#1617) When an equipped item is put on the ground (DROP, or ItemBounce of an item that doesn't fit in the backpack, eg. the STR check on an overweight char), CItem::MoveTo removes it from the char while inserting it in the sector, and that fires @Unequip. If the trigger moved the item elsewhere (CONT=, BOUNCE) or removed it, InsertContentTail already refused to insert it in the sector, but MoveTo went on: SetTopPoint cleared the container UID flags and overwrote the contained position of the item now in the backpack, and MoveToCheck set a ground decay timer on it. Debug builds asserted on 'pItem->GetParent() == this' in CItemsList::AddItemToSector. - CItemsList::AddItemToSector and CSector::MoveItemToSector report when the item wasn't added, and CItem::MoveTo returns false without placing it. - CItem::MoveToCheck stops there, without the update, decay timer and sound. - CChar::ItemBounce shows the "placed at your feet" message only if the item really ended on the ground.
|
While re-checking the null pointer handling, I found an edge case path that wasn’t covered: when an equipped item is dropped on the ground (DROP, or ItemBounce when it doesn’t fit in the backpack), @Unequip fires from inside CItem::MoveTo. If the trigger moves the item elsewhere or removes it, MoveTo still went on placing it on the ground, so it corrupted the position of the item now in the backpack and gave it a ground decay timer. The second commit (f51adfc) handles this: MoveTo stops if the item wasn’t added to the sector, and MoveToCheck skips the update, decay timer and sound. |
Description
When an equipped item is moved again while it is being unequipped (from inside its own
@Unequiptrigger), the removal runs twice. This happens in two ways:@Unequiplowers the STR below the REQSTR of the same item (e.g.SRC.MODSTR=<SRC.MODSTR> + -15).Stat_SetMod→Stat_StrCheckEquipthen bounces the item that is still linked to the char. That nested removal unequips it completely, and the outer removal does everything a second time.SRC.BOUNCE <UID>,CONT=,REMOVE.Results:
'pObjRec->GetParent() == this' CSObjCont.cpp:124.@DropOn_Item(e.g. the ScriptPack housing/mysticism scripts),ItemBouncefires@DropOn_Item. That resets the item's trigger recursion guard, so@Unequipfires over and over: 11 times in my tests, until the STR underflowed to 65523. With a script BOUNCE/REMOVE it ran until "Parsing ... HALTED ... recursively".Changes:
CItemgets an "unequipping" flag, set while its@Unequiptrigger runs (RAII guard inCChar::OnRemoveObj).Stat_StrCheckEquipskips that item, and@Unequipis not fired again for it.CChar::OnRemoveObjstops if the trigger already moved or deleted the item. It has already been fully unequipped by the nested removal.CSObjCont::InsertContentTailandCContainer::ContentAddPrivatenow returnbool. They return false if removing the record from its old container already moved it elsewhere (or deleted it).CChar::LayerAddandCItemContainer::ContentAddthen don't handle it as contained, and don't add its weight again.Type of Change
Related Issues
Fixes #1617
Testing
SetID→UnEquipAllItems), and@UnequipdoingSRC.BOUNCE,CONT=<backpack>orREMOVE.@Unequipfired 11× or until HALTED, and STR underflow.@Unequipfires once, the MODSTR/bonuses are correct, the item is once in the pack, the char and pack weights are correct, and there are no asserts.@Equip/@Unequip, a STR curse, then a script unequipping all layers. Before the fix there were duplicated items in the pack and phantom weight. After it, the weights are correct.Checklist
Additional Notes
@Unequipis no longer fired a second time for an item that is moved again from inside its own@Unequip. Before, this repeated firing was a bug: it re-applied the script effects and corrupted the stats.@DropOn_Itemfired from inside@Unequip) clears the guard, so the outer trigger can be entered again recursively.