Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Examples should call URuntimeMeshProvider::Shutdown in Actor EndPlay #2

@connorjak

Description

@connorjak

Not doing so can result in the URuntimeMesh's GPU buffers sticking around for quite a while until the URuntimeMesh finally gets garbage-collected for being unreachable.


Copy-pasted from my comment on the Discord:

I fixed my DEVICE REMOVED, REASON: HUNG issues! As it turns out, the symptom of the error was a VRAM overflow. I was destroying the actor that held the mesh immediately when it wasn't required. The URuntimeMesh object that a URuntimeMeshProvider subclass maintains wasn't being Reset() until the garbage collector eventually got around to deleting unreachable objects (happens infrequently). So, between garbage collections, I was basically leaking VRAM at 100s of MB/s when being aggressive with it.

I fixed this by calling URuntimeMeshProvider::Shutdown() on my provider (which ends up calling URuntimeMesh::Reset() during its corresponding actor's EndPlay().

//.h
UCLASS()
class SPACECRAFT_API APlanetQuadtreeSurface : public AActor
{
	GENERATED_BODY()

private:
	URuntimeMeshProviderCollision* collisionProvider;

	//NOTE: can move back to public if necessary
	PlanetContext context;

public:
	UPROPERTY(VisibleAnywhere)
	URuntimeMeshComponent* runtimeMeshComp;

	UPROPERTY(VisibleAnywhere)
	URuntimeMesh* runtimeMesh;

	UPROPERTY(VisibleAnywhere)
	UPlanetSurfaceMeshProvider* surfaceProvider;

//.cpp

void APlanetQuadtreeSurface::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	Super::EndPlay(EndPlayReason);

	// Deallocating the mesh buffers is something we can't wait on the
	// UObject garbage collection to do.
	surfaceProvider->Shutdown();

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions