Open PhDittmann opened 11 months ago
GES should only be called on game thread based on current design api. You're right however that the current implementation uses raw pointers a bit too liberally and thus can't properly detect when they are invalidated due to a garbage collection cycle. A refactor to smart pointers would likely alleviate this.
Atm you can typically guarantee pointer sanity by balancing calls with Unbind All Events for Context, but this is less than ideal API imo. We should be able to auto-detect invalid receivers on emit and cleanup (which is in theory how it currently works, but raw pointers...).
If you believe your changes above are all that are needed for the refactor, feel free to make a pull request, I'll run some tests and merge.
'Source/GlobalEventSystem/Public/GESHandlerDataTypes.h' defines
UObject* FGESMinimalEventListener.ReceiverWCO
, which points to UObjects in the scene, butListener.ReceiverWCO->IsValidLowLevelFast()
seems to fail regarding deleted objects.Spawning and deleting objects rapidly while triggering events leads to crashes:
In a first try I changed
ReceiverWCO
to a TWeakObjectPtr, which does not extend the lifetime of an object, but gets properly notified, when it gets deleted:With these changes I'm not able to reproduce the crashes, but I'm sure if it's really thread-safe or the way Epic intended. Here are some resources I found about this topic: