You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .context/patterns.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,81 @@ end)
122
122
123
123
**When to Apply**: Any time you need to hook mouse events on buttons that use `ContainerFrameItemButtonTemplate` or any button where clicks can trigger protected functions.
124
124
125
+
### Pattern: Never Manipulate Blizzard Frames from OnHide/OnShow Scripts Triggered by UISpecialFrames
126
+
**Problem**: Touching BankPanel or calling CloseBankFrame() from frame OnHide/OnShow scripts causes persistent taint that breaks UseContainerItem() for ALL containers (including backpack) after the bank is closed via ESC key.
127
+
128
+
**Why**: When ESC is pressed, WoW's engine calls `CloseSpecialWindows()` which iterates through `UISpecialFrames` and hides each frame. This hiding happens in a protected execution context. Any frame scripts (OnHide/OnShow) that execute during this process are still within the protected context. If these scripts touch Blizzard frames like BankPanel or call protected functions like CloseBankFrame(), they create persistent taint. Later, when the user opens their backpack and uses an item, Blizzard's protected `UseContainerItem()` calls `BankFrame:GetActiveBankType()` which reads from the tainted BankPanel, causing the action to be blocked.
129
+
130
+
**Solution Pattern**:
131
+
1.**Never touch BankPanel in OnHide/OnShow scripts** - move all BankPanel manipulation to event handlers
132
+
2.**Never call CloseBankFrame() in OnHide** - let Blizzard's CloseSpecialWindows handle it, or call it from event handlers
133
+
3.**Use BANKFRAME_OPENED/CLOSED event handlers** for safe BankPanel manipulation (these run in addon context, not protected context)
134
+
4.**Keep OnHide/OnShow scripts minimal** - only handle your own addon's UI cleanup (sounds, animations, frame hiding)
135
+
136
+
**Example**:
137
+
```lua
138
+
-- BAD: OnHide touches BankPanel (runs in protected context from UISpecialFrames)
139
+
functionbank.proto:OnHide()
140
+
addon.ForceHideBlizzardBags()
141
+
PlaySound(SOUNDKIT.IG_MAINMENU_CLOSE)
142
+
143
+
-- WRONG: These calls create persistent taint!
144
+
ifBankPanelthen
145
+
BankPanel:Hide() -- Taints BankPanel
146
+
end
147
+
ifC_Bankthen
148
+
C_Bank.CloseBankFrame() -- Duplicate call in protected context
149
+
end
150
+
end
151
+
152
+
-- GOOD: OnHide only handles own UI, no Blizzard frame manipulation
153
+
functionbank.proto:OnHide()
154
+
-- IMPORTANT: Do NOT touch BankPanel or call CloseBankFrame() here.
155
+
-- OnHide runs in protected context when triggered by UISpecialFrames (ESC key).
156
+
-- Any BankPanel manipulation here causes persistent taint.
0 commit comments