Skip to content

Fix cyclic TSharedPtr references causing memory leaks in item UI widgets#27

Draft
Copilot wants to merge 7 commits into
mainfrom
copilot/add-slate-inventory-canvas
Draft

Fix cyclic TSharedPtr references causing memory leaks in item UI widgets#27
Copilot wants to merge 7 commits into
mainfrom
copilot/add-slate-inventory-canvas

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

Slate widget trees had multiple cyclic TSharedPtr reference patterns preventing ref counts from ever reaching zero — widgets were never freed.

Cycles fixed

  • SNaItemSlot ↔ BoxSlot: Parent holds TSharedPtr<SNaBoxSlot>, child delegates held TSharedPtr back to parent via BindSP
  • SNaInventoryWrappedBox / SNaInventoryCanvas self-ref: BindEventsToUMG() called OnSlotXxx.AddSP(this, ...) on own member delegates — permanent self-reference
  • SNaInventoryCanvas ↔ child slots: Canvas owns slots via TSharedPtr, child BoxSlot delegates held TSharedPtr back to canvas via CreateSP

All resolved by switching to BindRaw/CreateRaw — safe because child widgets cannot outlive their parent in the Slate tree:

// Before: creates strong back-reference → cycle
BoxSlot->OnPointed.BindSP(this, &SNaItemSlot::SlotPointedToList);

// After: raw pointer, no ref count increment
BoxSlot->OnPointed.BindRaw(this, &SNaItemSlot::SlotPointedToList);

Additional fixes

  • UNaItemSlotList::List: TSharedRefTSharedPtr (TSharedRef has no default ctor / Reset())
  • UMGRef: Raw UObject*TWeakObjectPtr in both SNaInventoryWrappedBox and SNaInventoryCanvas, with validity checks in all SlotXxxToUMG() forwarders
  • SNaInventoryWrappedBox::Construct: UMGRef was never assigned from InArgs._FromUMGBindEventsToUMG() was always a no-op
  • SLATE_ATTRIBUTE type mismatches: Fixed broken types from recent rename (TSharedRef<FNaItemSlotStyle>FNaItemSlotStyle*, wrong Container type, invalid TWeakObjectPtr<UNaItemSlotList*> syntax)
  • SNaItemSlot::StylePtr: TSharedPtr<FNaItemSlotStyle> → raw pointer (style is stack-owned by UMG widget, TSharedPtr would double-free)
  • SNaItemSlot::ItemSlotList: TWeakPtr → raw pointer (child→parent back-ref; TWeakPtr can't be assigned from raw ptr, broke compilation)

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 3 commits February 27, 2026 18:45
…temInventoryWidget, etc.)

Co-authored-by: SodiumZH <46860829+SodiumZH@users.noreply.github.com>
Co-authored-by: SodiumZH <46860829+SodiumZH@users.noreply.github.com>
Co-authored-by: SodiumZH <46860829+SodiumZH@users.noreply.github.com>
Copilot AI changed the title [WIP] Add slate widget for custom inventory canvas Add SNaInventoryCanvas and UNaInventoryCanvas for canvas-based inventory UI Feb 27, 2026
- SNaItemSlot: BindSP→BindRaw/CreateRaw in BoxSlot delegate bindings to break parent↔child cycle
- SNaInventoryWrappedBox: AddSP→AddRaw in BindEventsToUMG to break self-referential cycle
- SNaInventoryCanvas: BindSP/CreateSP→BindRaw/CreateRaw in both BindSlotEvents and BindEventsToUMG
- NaItemSlotList UMG: TSharedRef→TSharedPtr for List member (TSharedRef has no default ctor/Reset)
- Fix broken SLATE_ATTRIBUTE types in SNaInventoryWrappedBox and SNaItemSlot headers
- Add UMGRef assignment in SNaInventoryWrappedBox::Construct (was never set)
- Change UMGRef to TWeakObjectPtr in SNaInventoryWrappedBox and SNaInventoryCanvas
- Add validity checks in all SlotXxxToUMG() functions

Co-authored-by: SodiumZH <46860829+SodiumZH@users.noreply.github.com>
Copilot AI changed the title Add SNaInventoryCanvas and UNaInventoryCanvas for canvas-based inventory UI Fix cyclic TSharedPtr references causing memory leaks in item UI widgets Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants