ReferenceChainSearch Crash on Stop Play

I have a strange problem since I ported my project to 4.8:

Everything works fine until I press ‘Stop Play’ after playing in editor. At that point the editor crashes with the following error message:
[2015.06.17-18.40.25:611][308]LogWindows: === Critical error: ===
Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.8\Engine\Source\Runtime\CoreUObject\Private\UObject\ReferenceChainSearch.cpp] [Line: 633]
Unknown token

I did some experimenting and found out that I can prevent the crash by not declaring a TArray as UPROPERTY in a certain UClass. The structure is the following:

In the GameState I create a custom UClass responsible for keeping track of who is targeting who. The Gamestate.cpp looks like this:

ACGameState::ACGameState(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	targetManager = NewObject<UCTargetManager>(UCTargetManager::StaticClass(), "TargetManager");
}

The relevant part of the TargetManager.cpp looks like this: (I omitted a lot of code but I made sure this is all code that is actually called during the testing.)

int UCTargetManager::RegisterObject(ACSpaceObject* newObject)
{
	int newID = counter;
	counter += 1;
	KnownObjects.Add(newObject);
	return newID;
}

The corresponding TargetManager.h file looks like this: (Again, all non relevant parts are omitted.)

UCLASS()
class UNREAL_SPACE_API UCTargetManager : public UObject
{
	GENERATED_BODY()
	
private:

	UPROPERTY()
	int32 counter = 0;

	//Array holding all known objects.
	UPROPERTY()
	TArray<ACSpaceObject*> KnownObjects;
}

Every ACSpaceObject calls the TargetManager’s RegisterObject method in the BeginPlay method.

Running the project like this causes the crash as soon as I press ‘Stop Play’. If I remove the last UPROPERTY() statement from the TargetManager.h file everything works fine.

Is this some kind of bug or am I doing something wrong.

I attached the last log file and the corresponding dump.
link text

I tried a few more things:

To make sure the source of the issue is not a corrupted asset somewhere in the project I created a new project and copied the source code to the new project… The content folder is completely empty but the error persists.

Hi ,

It seems that the issue that is occurring when you press Stop is that the editor is throwing out an error due to not being able to completely clean up UWorld. The reason why could be that this TArray’s Outer is set to something that isn’t being cleaned up, so the TArray itself isn’t either. Can you try replacing the line in your constructor with the following?

targetManager = NewObject<UCTargetManager>(this, UCTargetManager::StaticClass(), "TargetManager")

Adding the ‘this’ at the beginning of the parameters for the function is setting the Outer of targetManager to the ACGameState object.

Hope this helps!

Awesome! That did it. Thank you very much.