Skip to content

Commit ae825b7

Browse files
committed
fix(vanilla): error during item unequip if any skill accesses item skill
In vanilla clearSkills() calls container.remove(skill) on each skill in SkillPtrs which triggers an immediate removal and skill_container.update on each iteration. This leads to the issue if someone accesses this item's skills during skill.onUpdate it will provide skills which have already been removed from the container leading to an error when you try skill.getContainer().something. Vanilla bug report: https://steamcommunity.com/app/365360/discussions/1/604159344068529469/
1 parent a5a1a3a commit ae825b7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

msu/hooks/items/item.nut

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@
6060
return names != "" ? "[color=" + ::Const.UI.Color.NegativeValue + "]" + names.slice(0, -2) + "[/color]\n\n" + __original() : __original();
6161
}
6262

63+
// VanillaFix: https://steamcommunity.com/app/365360/discussions/1/604159344068529469/
64+
// SkillPtrs having skills which have been removed from skill_container.
65+
// In vanilla clearSkills() calls container.remove(skill) on each skill in SkillPtrs
66+
// which triggers an immediate removal and skill_container.update on each iteration.
67+
// This leads to the issue if someone accesses this item's skills during skill.onUpdate
68+
// it will provide skills which have already been removed from the container leading
69+
// to an error when you try skill.getContainer().something.
70+
q.clearSkills = @() function()
71+
{
72+
if (this.getContainer() == null || this.getContainer().getActor() == null || this.getContainer().getActor().isNull())
73+
{
74+
return;
75+
}
76+
77+
// Instead of vanilla style of .remove(skill) we just set the skill to garbage
78+
// and then collect garbage after SkillPtrs have been cleared so that the
79+
// skill_container.update happens after the SkillPtrs are properly empty.
80+
foreach (skill in this.m.SkillPtrs)
81+
{
82+
skill.removeSelf();
83+
}
84+
85+
this.m.SkillPtrs = [];
86+
87+
this.getContainer().getActor().getSkills().collectGarbage();
88+
}
89+
6390
q.onAfterUpdateProperties <- function( _properties )
6491
{
6592
}

0 commit comments

Comments
 (0)