Skip to content

Commit bd40d57

Browse files
committed
bank frame closes on esc and more docs
1 parent 451a0ed commit bd40d57

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

.context/patterns.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ end)
129129

130130
**Solution Pattern**:
131131
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)
132+
2. **Never call CloseBankFrame() in OnHide** - it runs in protected context and causes taint
133+
3. **DO call CloseBankFrame() in CloseSpecialWindows SecureHook** - this is safe and necessary to exit banking mode
134+
4. **Use BANKFRAME_OPENED/CLOSED event handlers** for safe BankPanel manipulation (these run in addon context, not protected context)
135+
5. **Keep OnHide/OnShow scripts minimal** - only handle your own addon's UI cleanup (sounds, animations, frame hiding)
135136

136137
**Example**:
137138
```lua
@@ -170,6 +171,27 @@ function bank.proto:OnHide()
170171
end
171172
end
172173

174+
-- GOOD: Call CloseBankFrame() in CloseSpecialWindows hook (safe context)
175+
function addon:CloseSpecialWindows(interactingFrame)
176+
if interactingFrame ~= nil then return end
177+
178+
local ctx = context:New('CloseSpecialWindows')
179+
addon.backpackShouldClose = true
180+
181+
-- ... other cleanup ...
182+
183+
-- Call CloseBankFrame() to exit banking mode and trigger BANKFRAME_CLOSED event.
184+
-- This is safe here (SecureHook runs after Blizzard's function completes).
185+
-- CRITICAL: Do NOT call this from OnHide - that runs in protected context!
186+
if C_Bank then
187+
C_Bank.CloseBankFrame()
188+
else
189+
CloseBankFrame()
190+
end
191+
192+
events:SendMessageLater(ctx, 'bags/OpenClose')
193+
end
194+
173195
-- GOOD: BankPanel manipulation in event handler (safe context)
174196
function addon.CloseBank(ctx, _, interactingFrame)
175197
if interactingFrame ~= nil then return end
@@ -187,6 +209,11 @@ function addon.CloseBank(ctx, _, interactingFrame)
187209
end
188210
```
189211

212+
**Key Distinction**:
213+
-**OnHide script**: Runs in protected context (from UISpecialFrames) - touching BankPanel or calling CloseBankFrame() here CAUSES TAINT
214+
-**CloseSpecialWindows SecureHook**: Runs after Blizzard's function completes, in addon context - safe to call CloseBankFrame()
215+
-**BANKFRAME_CLOSED event handler**: Runs in addon context - safe to hide BankPanel
216+
190217
**When to Apply**:
191218
- Any time implementing custom bank frame behavior with UISpecialFrames registration
192219
- When hooking CloseSpecialWindows or handling BANKFRAME_OPENED/CLOSED events

core/hooks.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,14 @@ function addon:CloseSpecialWindows(interactingFrame)
126126
end
127127
events:SendMessage(ctx, 'addon/CloseSpecialWindows')
128128

129-
-- Don't call CloseBankFrame() here - Blizzard's CloseSpecialWindows() already
130-
-- handles closing the bank if it's open. Our BANKFRAME_CLOSED handler will
131-
-- clean up BankPanel safely.
129+
-- Call CloseBankFrame() to exit banking mode and trigger BANKFRAME_CLOSED event.
130+
-- This is safe here (SecureHook runs after Blizzard's function completes).
131+
-- CRITICAL: Do NOT call this from OnHide - that runs in protected context and causes taint.
132+
if C_Bank then
133+
C_Bank.CloseBankFrame()
134+
else
135+
CloseBankFrame()
136+
end
132137

133138
events:SendMessageLater(ctx, 'bags/OpenClose')
134139
end

0 commit comments

Comments
 (0)