VS2013 crashes during UObject construction

enum class CurrentTileType : char
{
NONE,
BLOCKING_TILE,
STRONG_BLOCKING_TILE,
GROUPED_BLOCKING_TILE
};

    UCLASS()
    class PROJECTTAP_API ATilesManager : public AActor
    {
    	GENERATED_BODY()
    	TArray<class ABlockingTile*> activatedBlocks;
    	TArray<class AGroupedBlockingTile*> activatedGroupedBlocks;
    	class AStrongBlockingTile* prevStrongBlockingTile;
    	bool isMousePressed = false;
    
    	unsigned char size_limit{ 3 };
    	unsigned char grouped_size_limit{ 6 };
    	CurrentTileType currentTileType{ CurrentTileType::NONE };
    
    	void UpdateGroupedBlockingTiles();
    
    	void SetBlockingTileCurrent();
    	void SetStrongBlockingTileCurrent();
    	void SetGroupedBlockingTileCurrent();
    
    	void DeactivateBlockingTiles();
    	void DeactivateGroupedBlockingTiles();
    public:
    	
    	void AddTile(ABlockingTile* tile);
    	void AddTile(AStrongBlockingTile* tile);
    	void AddTile(AGroupedBlockingTile* tile);
    	void DeactivateStrongBlockingTile();
    	void SetEnableSwipeCheck(bool b);
    
    	// Sets default values for this actor's properties
    	ATilesManager();
    
    	// Called when the game starts or when spawned
    	virtual void BeginPlay() override;
    	
    	// Called every frame
    	virtual void Tick( float DeltaSeconds ) override;
    
    	
    	
    };

I’m mostly sure it’s some code in the class above that’s causing the problem.

vs2013 crashes in the following place when I try to launch the editor with F5

UObject::UObject()
{
	FObjectInitializer* ObjectInitializerPtr = FTlsObjectInitializers::Top();
	UE_CLOG(!ObjectInitializerPtr, LogUObjectGlobals, Fatal, TEXT("%s is not being constructed with either NewObject, NewNamedObject or ConstructObject."), *GetName());
	FObjectInitializer& ObjectInitializer = *ObjectInitializerPtr;
	check(!ObjectInitializer.Obj || ObjectInitializer.Obj == this);//crashes
	const_cast<FObjectInitializer&>(ObjectInitializer).Obj = this;
	const_cast<FObjectInitializer&>(ObjectInitializer).FinalizeSubobjectClassInitialization();
}

What do you mean VS2013 crashes? when you compile? i think you mean editor crashing and VS debugger shows you the point where it happens. Check call stack and find what calls the constructor, because it looks like it’s not direct cause of crash. Maybe you initiating object in wrong way.

yeah, you are right. The editor crashes and the debugger shows the crash location.The crash occurs when I try to launch the editor inside of the VS2013

So the call stacks shows it went wrong when constructing TileManager.

I see sometimes the constructors get FObjectInitializer, don’t know why it’s there or how it works, delete it in some classes but things still work. Wonder if that’s the cause.

I didn’t do anything in the tileManager constructor though,can’t figure out why

    ATilesManager::ATilesManager()
    {
     	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = true;
    
    }

I solved the problem.

Seems like you can’t have an UObject sitting in the program image. I think any Uobject has to be on the heap and be referenced by a pointer.

I made tileManager a pointer type and the crash no longer takes place. I think this is maybe a bug and would be nice to have a more informative error information.

I should make it clear.

I have a reference of TileManager in the other class, and it is not a pointer type. Unreal can’t construct an UObject type without using built in instantiate methods so the editor crashed.

in one word, always reference UObject by a pointer

Thats what i meant by “initiating wrong” :slight_smile: