UE4.13 crashes when using more than 1gb ram

I made a new c++ project in ue 4.13.
After loading the project ue consumes about 0.8gb.
When I hit play, I spawn a few blueprints:

h:

UPROPERTY(EditDefaultsOnly, Category = "Generation settings")
TArray<TSubclassOf<ARoom>> Rooms;

cpp:

FActorSpawnParameters spawnParams;				
spawnParams.Owner = this;						
spawnParams.Instigator = Instigator;		

FVector vec;									
vec.Set(0, 0, 0);

ARoom* activeRoom = Cast<ARoom>(Rooms[roomNr]);

AActor* newActor = GetWorld()->SpawnActor<ARoom>(Rooms[0], vec, FRotator::ZeroRotator, spawnParams);

The more blueprints I spawn, the more ram UE uses (as expected). But when I’m just about to pass the 1gb mark UE closes (no error message).

The static mesh of the room is very basic:

107421-room.png

PC specs:

107422-specs.png

What am I doing wrong?

Edit:

Project setup:
C++/FPS

  • Added both classes to the project
  • Created Blueprints based on Room and Room_Controller
  • Added a static mesh to the Room bp
  • Added the Room bp to the Room_Controller bp (Rooms)
  • Compile and hit play
  • If ue uses less then 1 gb of ram 2 rooms are spawned
  • Else ue closes itself

The full classes:

Room.h

#pragma once

#include "GameFramework/Actor.h"
#include "Room.generated.h"

UCLASS()
class SILENTSPACE_API ARoom : public AActor
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	ARoom();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	// Called every frame
	virtual void Tick(float DeltaSeconds) override;

	UPROPERTY(EditDefaultsOnly, Category = "Room settings")
	int DoorCount = 1;

	UPROPERTY(EditDefaultsOnly, Category = "Room settings")
	TArray<FVector> DoorPositions;

	UPROPERTY(EditDefaultsOnly, Category = "Room settings")
	FVector RoomSize;
};

Room.cpp

#include "SilentSpace.h"
#include "Room.h"


// Sets default values
ARoom::ARoom()
{
	// 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;
}

// Called when the game starts or when spawned
void ARoom::BeginPlay()
{
	Super::BeginPlay();

	if(DoorPositions.Num() != DoorCount)
		UE_LOG(LogTemp, Warning, TEXT("DoorPositions.Num() != DoorCount"));
}

// Called every frame
void ARoom::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

Room_Controller.h

#pragma once

#include "GameFramework/Actor.h"
#include "Room.h"
#include "Room_Controller.generated.h"

UCLASS()
class SILENTSPACE_API ARoom_Controller : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ARoom_Controller();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick(float DeltaSeconds) override;

	// Generates the maze
	bool Generate(int maxRooms);
	
protected:
	UPROPERTY(EditDefaultsOnly, Category = "Generation settings")
	int MaxRooms = 5;

	UPROPERTY(EditDefaultsOnly, Category = "Generation settings")
	TArray<TSubclassOf<ARoom>> Rooms;
};

Room_Controller.cpp

#include "SilentSpace.h"
#include "Room_Controller.h"


// Sets default values
ARoom_Controller::ARoom_Controller()
{
	// 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;
}

// Called when the game starts or when spawned
void ARoom_Controller::BeginPlay()
{
	Super::BeginPlay();

	Generate(MaxRooms);								//Generate a maze with a max of 5 rooms
}

// Called every frame
void ARoom_Controller::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Generates the maze
bool ARoom_Controller::Generate(int maxRooms)
{
	UE_LOG(LogTemp, Warning, TEXT("DoorCount"));

	const UWorld* world = GetWorld();				//Check if the world exists

	if (!world)
		return false;

	FActorSpawnParameters spawnParams;				//Create spawn params
	spawnParams.Owner = this;						//Set the owner
	spawnParams.Instigator = Instigator;			//Set who can do dmg to the object

	FVector vec;									//Create a vector
	vec.Set(0, 0, 0);

	int roomNr = FMath::RandRange(0, Rooms.Num());	//Create a random nr between 0 and max different rooms

	ARoom* activeRoom = Cast<ARoom>(Rooms[roomNr]);

	//Spawn the new room
	AActor* newActor = GetWorld()->SpawnActor<ARoom>(Rooms[0], vec, FRotator::ZeroRotator, spawnParams);

	vec.Set(1000, 0, 0);
	GetWorld()->SpawnActor<ARoom>(Rooms[0], vec, FRotator::ZeroRotator, spawnParams);

	for (int i = 0; i < maxRooms; i++)
	{

	}

	return true;
}

What is the total usage of RAM? Any errors?

Without UE running im at 4.7 gb used. No errors.

It’s strange, my UE4.13 project use on startup 1.5Go and can go to 2.5 without any trouble …

Hey 91378246-

Where is the code that you posted being added / called? What does the code for your ARoom class look like? If you’re able to reproduce the crash in a new project, please provide the setup steps to help investigate locally.

I added the full classes and the setup steps.

Hey 91378246-

Based on the code provided I did receive a crash in the editor. However my crash was caused by an array out of bounds error that I tracked to the use of RandRange in Room_Controller.cpp. When you call RandRange it will return a number from A to B, including A and B. If your Rooms array has five entries then RandRand can return anything between 0-5. However those five array elements are numbered from 0 - 4. The crash comes from the following line where this random number is used. If the RandRand call returns a value of 5, then when this is used in the following cast it causes the crash. You can avoid this by editing the RandRange call as such: int roomNr = FMath::RandRange(0, Rooms.Num()-1);. The - 1 at the end will ensure that the random number will be within the valid array elements.

Cheers

Doug Wilson