Hey all,
Wanted to report this odd exception that showed up.
The exception was thrown by the garbage collection code in ConditionalBeginDestroy() when I attempt to delete an actor (in the level editor, not through code) that I allocated a dynamic object in and manually freed.
The odd thing is when this class wasn’t inheriting from a base class I had defined and instead directly from AActor, this bug did not happen.
The exception was thrown by an IsValidLowLevel() check so I’m assuming it is because the Garbage Collector was trying to free already freed memory (i.e. the object I dynamically allocated and then freed).
If I do not attempt to manually free the object, no exception is thrown.
Code is provided below.
void AProceduralTerrainActor::OnConstruction(const FTransform& Transform)
{
UE_LOG(LogTemp, Warning, TEXT("In OnConstruction!"));
Super::OnConstruction(Transform);
if (HeightmapTexture != NULL)
{
// Needed for first time construction
if (!bIsHeightMapBuilt)
{
UE_LOG(LogTemp, Warning, TEXT("Constructing Heightmap!"));
// Create heightmap builder and set reference
UHeightmapBuilder* builder = NewObject<UHeightmapBuilder>();
builder->SetTerrainReference(*this);
builder->CreateHeightmapFromActorReference();
bIsHeightMapBuilt = true;
// Deallocate builder object
//FMemory::Free(builder); <----- If this is uncommented, throws an exception in ConditionalBeginDestroy()
}
GenerateMeshFromHeightmap();
}
else
{
GenerateDefaultMesh();
}
}