Crash using TActorIterator with AsyncLoadingThreadEnabled

This is a strange crash, as a Cast operation is failing to cast an actor blueprint to AActor, and the source item is definitely not null. It appears that IsAUsingFastTree() is failing, and my only hypothesis is that the state of FFastIndexingClassTreeRegistrar::ClassTreeIndex is getting out of sync between a class and its parent. There is no lock held on FFastIndexingClassTree::StateType::ClassesCriticalSection anywhere aside from registering new types, which means the loops inside FFastIndexingClassTree::Register will modify one class at a time, and any other thread may those values in an inconsistent state. As with most threading bugs, this one is sporadic and rare but fatal when it happens.

We have disabled async loading thread for stability although it causes hitching during play. A simple fix may be adding a lock inside IsAUsingFastTree() but that would be quite costly, so perhaps a write lock mechanism on Register() for ClassesCriticalSection and a lock around each thread entry loop would address the issue.

Log output:

[2016.05.13-21.27.01:446][191]LogLevel: ActivateLevel /Game/Maps/Common/PlaceholderMapName 1 1 0
[2016.05.13-21.27.01:461][193]LogWindows:Error: Windows GetLastError: The operation completed successfully. (0)
[2016.05.13-21.27.02:428][193]LogWindows:Warning: CreateProc failed (2) ..\..\..\Engine\Binaries/Win64/CrashReportClient.exe  -AppName=UE4-App
[2016.05.13-21.27.02:430][193]LogWindows: Could not start CrashReportClient.exe
[2016.05.13-21.27.02:430][193]LogMemory: Platform Memory Stats for WindowsNoEditor
[2016.05.13-21.27.02:431][193]LogMemory: Process Physical Memory: 1011.66 MB used, 1065.01 MB peak
[2016.05.13-21.27.02:432][193]LogMemory: Process Virtual Memory: 4764.36 MB used, 4797.27 MB peak
[2016.05.13-21.27.02:434][193]LogMemory: Physical Memory: 8093.21 MB used, 65437.78 MB total
[2016.05.13-21.27.02:435][193]LogMemory: Virtual Memory: 5507.43 MB used, 134217728.00 MB total
[2016.05.13-21.27.15:913][193]LogWindows:Error: === Critical error: ===
Fatal error: [File:C:\App\Stable\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\Templates\Casts.cpp] [Line: 11] 
Cast of BP_Sky_SphereTest_C /Game/Maps/GM_Map_01/GM_Map_01_Lighting.GM_Map_01_Lighting:PersistentLevel.BP_Sky_SphereTest to Actor failed

Call stack top:

App.exe!FOutputDeviceWindowsError::Serialize(const wchar_t * Msg, ELogVerbosity::Type Verbosity, const FName & Category) Line 95	C++
App.exe!FOutputDevice::Logf__VA(const wchar_t * Fmt, ...) Line 143	C++
App.exe!FDebug::AssertFailed(const char * Expr, const char * File, int Line, const wchar_t * Format, ...) Line 374	C++
App.exe!CastLogError(const wchar_t * FromType, const wchar_t * ToType) Line 11	C++
App.exe!CastChecked<AActor,AActor>(AActor * Src, ECastCheckedType::Type CheckType) Line 195	C++
App.exe!AAppHUD::Update() Line 1063	C++

Hey -

I am not familiar with the TActorIterator, would it be possible for you to provide a sample project that demonstrates the bug you’re having and/or provide detailed setup steps so that I can try to create a reproduction of the issue locally? Additionally, if you are using source code and have a solution to the issue that works for you, you can also submit a pull request on Github to potentially have your fix included in the engine. You can use this link to submit the pull request:

https://github.com/EpicGames/UnrealEngine/compare?expand=1

Hi ,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

I’m actually running into what I think is the same issue. I’ve recently turned on AsyncLoadingThreadEnabled, and I’m now getting crashes from the CastChecked<> function that clearly should cast correctly.

Like sometimes when GetWorld() is called, when it calls GetLevel(), CastChecked( GetOuter() ), it is failing to cast the PersistentLevel to a ULevel.

This occurs when we are marking levels to stream, so while our AsyncLoadingThread is running.

App.exe!CastLogError(const wchar_t * FromType, const wchar_t * ToType) Line 11	C++
App.exe!CastChecked<ULevel,UObject>(UObject * Src, ECastCheckedType::Type CheckType) Line 195	C++
App.exe!AActor::GetWorld() Line 278	C++
App.exe!APlayerController::GetHitResultAtScreenPosition(const FVector2D ScreenPosition, const ECollisionChannel TraceChannel, const FCollisionQueryParams & CollisionQueryParams, FHitResult & HitResult) Line 1932	C++
App.exe!APlayerController::GetHitResultAtScreenPosition(const FVector2D ScreenPosition, const ECollisionChannel TraceChannel, bool bTraceComplex, FHitResult & HitResult) Line 1942	C++
App.exe!FWidget3DHitTester::GetHitResultAtScreenPositionAndCache(APlayerController * PlayerController, FVector2D ScreenPosition) Line 419	C++
App.exe!FWidget3DHitTester::GetBubblePathAndVirtualCursors(const FGeometry & InGeometry, FVector2D DesktopSpaceCoordinate, bool bIgnoreEnabledStatus) Line 327	C++
App.exe!FHittestGrid::GetWidgetPathAndDist(const FHittestGrid::FGridTestingParams & Params, const bool bIgnoreEnabledStatus) Line 620	C++
App.exe!FHittestGrid::GetBubblePath(FVector2D DesktopSpaceCoordinate, float CursorRadius, bool bIgnoreEnabledStatus) Line 143	C++

I’ve had other callstacks of calling GetWorld() reaching a CastChecked<> fail, as well as UMG UTextProperty failing to do a normal Cast<> to a UProperty in GetValueRecursive() of DynamicPropertyPath.h. Which results in the else attempting to do a CastChecked<> to a function which clearly fails.

Currently on 4.11

Hey Decterous-

Can you provide the full callstack from your crash as well as what you were doing when the crash occurred (Play in editor, changing levels, etc.)? If possible, could you also provide steps to reproduce the crash in a new project?

I’ve attached one of the callstacks.

All I was doing was marking several streaming levels bShouldBeLoaded as true.
Once they load I move my character to the new area, but while it is loading I was doing nothing.

There are two crashes that are happening, and this one already occurs so rarely. I could try setting up a new project, but I’d need things to stream in and I’d just be streaming in the levels/objects I’ve already set up.

link text

Hey Decterous-

Just to be clear, are you crashing when moving the character or when attempting to load the level? Can you post a screenshot of the setup you’re using to check the Should Be Loaded boolean and verifying that the level has been properly loaded?

I just made my own version of FStreamLevelAction.

It takes a list of levels instead of just one, and does UpdateLevel() which if any of the levels return false then we just continue along like it does for the single levels.

Specifically it is happening when loading the level. I fade to black before moving the character and that fade never happens.

Hey Decterous-

Just for a sanity check, can you let me know if you still get a crash using the original version of FStreamLevelAction to stream one level at a time? If you are still getting it a crash, it would be helpful if you could provide exact setup steps to reproduce the crash or provide a sample project for me to test locally.

Ran in the same problem here with AsyncLoadingThreadEnabled.

Did this patch solved your issues by any chance ?

Thanks!