This isnt any safer. The IsValid is check will fail or succeed in the same way each time
A user reported a one-time crash that possibly occurred when a TWeakPtr became invalid immediately after passing an IsValid check, before the TWeakPtr could be used. The SViewport.cpp file contains several instances of code that uses the following pattern:
The user suggested that this code may be better written as follows:
Please investigate whether using Pin prior to IsValid in these cases would be better able to prevent a potential race condition.
Note: I was unable to repro the actual crash that the user experienced, and they apparently only saw it happen a single time.
The code in the first code snippet shown in the Description is visible.
The code in the second code snippet shown in the Description may be safer.
Head over to the existingAnswerHub thread and let us know what's up.