@@ -129,9 +129,10 @@ end)
129129
130130** Solution Pattern** :
1311311 . ** 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
171172end
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)
174196function addon .CloseBank (ctx , _ , interactingFrame )
175197 if interactingFrame ~= nil then return end
@@ -187,6 +209,11 @@ function addon.CloseBank(ctx, _, interactingFrame)
187209end
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
0 commit comments