Developer Notes

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:

if (ViewportInterface.IsValid())

The user suggested that this code may be better written as follows:

TSharedPtr<ISlateViewport> PinnedInterface = ViewportInterface.Pin();
if (PinnedInterface.IsValid())

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.

Steps to Reproduce
  1. Open the UE4.sln file in Visual Studio.
  2. Open the SViewport.cpp file.
  3. Locate the SViewport::OnMouseLeave function.

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.

Have Comments or More Details?

Head over to the existingAnswerHub thread and let us know what's up.

Login to Vote

Won't Fix
Affects Versions4.
CreatedAug 31, 2015
ResolvedSep 1, 2015
UpdatedJun 14, 2016