I am working on Slate Widget containing a Dropdown Menu to select between different Enum Values. Due to me not finding any native approach to display an Enum Selector (If anyone could provide an easy solution that would probably fix my problem) I use a setup where I fill a TArray with “MakeShareable(new EMyEnum(MyEnum)” on each enum-value via a TEnumRange iterator. The TArray is stored as a class member and is provided to an SComboBox as its OptionsSource. This works fine for all enum-values except for 1 specific value named “NorthEastCorner”. The value the pointer is pointing to is correct during the Construct() function, but after leaving the scope the value gets modified (values I found were always a multiple of 2). I experimented a bit and found that the value reacts to size-changes of the logging tab (Just the small default tab that opens from below, not a custom logging DockTab). The changes did not appear consistent with its size and I can’t make out any correlation between the new value and the tab size change. This behavior only happens for the one specific Enum name out of 13 (+1 Uninitialized for RANGE_BY_COUNT). Explicitly adding “= value” to the enum didn’t change anything, and when switching the order of the enum names, the error reappeared at the new index where I placed the name NorthEastCorner. After renaming the NorthEastCorner to NorthEastCornerTest the error disappeared and everything worked fine. Looking for answers I undid the rename and tried again. To my surprise, everything worked with the original name. One rebuild later however the same thing as before happened. Also, since this error my Editor has not been closing properly and I have to shut it down manually via TaskManager, I assume this has something to do with it (The invalid enum value is stored in another class member but is contained from there). Does anyone have suggestions on what might cause such behavior?
I solved it myself:
I stored an Initial Selection value (TSharedPtr), which I directly assigned from the EnumPtr created by MakeShareable. Due to MakeShareable returning a TRawPtrProxy which is implicitly convertable to a TSharedPtr and not directly a TSharedPtr, and me being lazy and using auto typing, the value I assigned to the Initial Selection was not a copy of the TSharedPtr but a copy of the TRawPtrProxy. This meant that once the Initial Selection was not referenced anymore (i.e. different item selected) the SharedPtr gave free the memory as it was the only reference it knew of. This then led to use after free by the other TSharedPtr. I still can’t explain the thing working after renaming the enum, but maybe that was just pure fool’s luck that the memory was not being used elsewhere
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.