# Fatal error after deleting a component with media texture: A FRenderResource was deleted without being released first!

**URL:** <https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123>\
**Category:** Rendering\
**Tags:** unreal-engine, crash, bug-report, packaging-projects, Rendering, question\
**Created:** [September 21, 2016, 2:07am UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123 "2016-09-21T02:07:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_f60d77b1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f60d77b1](https://forums.unrealengine.com/u/anonymous_user_f60d77b1)\
**Post date:** [September 21, 2016, 2:07am UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/1 "2016-09-21T02:07:35Z")

</div>

After I deleting a component with media texture (Actually I destroyed an actor, and the component is attached to the root component of this actor), the game crash with follow reports:

Fatal error: [File:D:\Build++UE4+Release-4.13+Compile\Sync\Engine\Source\Runtime\RenderCore\Private\RenderResource.cpp] [Line: 118]  
A FRenderResource was deleted without being released first!

someProject!FDebug::AssertFailed()  
someProject!FMediaTextureResource::~FMediaTextureResource()  
someProject!FMediaTextureResource::`scalar deleting destructor’()  
someProject!UTexture::FinishDestroy()  
someProject!UObject::ConditionalFinishDestroy()  
someProject!IncrementalPurgeGarbage()  
someProject!UWorld::Tick()  
someProject!UGameEngine::Tick()  
someProject!FEngineLoop::Tick()  
someProject!GuardedMain()  
someProject!GuardedMainWrapper()  
someProject!WinMain()  
someProject!\_\_scrt\_common\_main\_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe\_common.inl:264]  
kernel32  
ntdll

BTW. This only happens in packaged game. When I play it in Editor, everything works fine.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f60d77b1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f60d77b1](https://forums.unrealengine.com/u/anonymous_user_f60d77b1)\
**Post date:** [September 21, 2016, 2:32am UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/2 "2016-09-21T02:32:52Z")

</div>

Some more information, the material is created dynamic during runtime.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0c62419a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0c62419a](https://forums.unrealengine.com/u/anonymous_user_0c62419a)\
**Post date:** [September 21, 2016, 3:02pm UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/3 "2016-09-21T15:02:32Z")

</div>

Hi Adcentury,

I was unable to reproduce your issue. Here is a list of steps that I tried.

1. Opened a blank 4.13 project
2. Added a sample mp4 video to the content folder
3. Created a Media source and Media Player asset and associated the Media source to the sample video
4. Played the Media Player so that a media texture was generated and create a material using the media texture
5. Create an Actor BP with a static mesh component
6. In the construct script create a dynamic material instance using the Media Texture Material as a base
7. In the even graph on begin play apply the dynamic material to the static mesh
8. Place the Actor BP in the level
9. In the level BP get a reference to the Actor BP placed in the level then delete the actor on event begin play
10. Package Project for windows 64 bit

It would be useful to know what platform you are packaging on as well as if you can reproduce this issue in a blank project.

,

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f60d77b1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f60d77b1](https://forums.unrealengine.com/u/anonymous_user_f60d77b1)\
**Post date:** [September 22, 2016, 9:39am UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/4 "2016-09-22T09:39:52Z")

</div>

SampleProject

Hi,

I have uploaded a minimal project to reproduce the issue. You can follow these steps to reproduce it:

1. Package this project for windows 64 bit
2. Copy “[PROJECT\_DIR]/Saved/users/sample.wmv” to “[PACAKGE\_GAME\_DIR]/MediaTextureCrash/Saved/users/sample.wmv”
3. Open the game and wait for 5 seconds. A cube with a video playing will appear (and you can hear the sound). Wait another 10 seconds, the cube will disappear (because the actor is destroyed).
4. Wait for about 2 min, then the game will crash and show the crash report.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f60d77b1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f60d77b1](https://forums.unrealengine.com/u/anonymous_user_f60d77b1)\
**Post date:** [September 22, 2016, 9:40am UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/5 "2016-09-22T09:40:21Z")

</div>

The project only contain 3 cpp class.

**MyLevelScriptActor**

This is used to create MyActor at begin play.

**MyActor**

a), Create MyStaticMeshComponent after about 5 seconds. Attach the component to self root component. and then LoadMedia of the component.

```
if (!bComponentAdded)
{
	if (count < 500)
	{
		count++;
	}
	else
	{
		MyComponent = UMyStaticMeshComponent::CreateComponent(this);
		MyComponent->RegisterComponent();
		MyComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetIncludingScale);

		MyComponent->LoadMedia();

		bComponentAdded = true;
		count = 0;
	}
}

```

b). Destroy self after another 10 seconds.

```
else
{
	if (count < 1000)
	{
		count++;
	}
	else
	{
		Destroy();
	}
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f60d77b1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f60d77b1](https://forums.unrealengine.com/u/anonymous_user_f60d77b1)\
**Post date:** [September 22, 2016, 9:40am UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/6 "2016-09-22T09:40:44Z")

</div>

**MyStaticMeshComponent**

a). A factory to create itself

```
UMyStaticMeshComponent* UMyStaticMeshComponent::CreateComponent(UObject* InOuter)
{
	UMyStaticMeshComponent* component = NewObject<UMyStaticMeshComponent>(InOuter);
	
	UStaticMesh* mesh = LoadObject<UStaticMesh>(NULL, TEXT("StaticMesh'/Game/Temp/SM_Mesh.SM_Mesh'"));

	component->SetStaticMesh(mesh);
	component->SetMobility(EComponentMobility::Movable);

	return component;
}

```

b). In LoadMedia method, it create a UFileMediaSource from local file (which is sample.wmv)

```
IFileManager& fileManager = IFileManager::Get();
FString videoPath = FPaths::ConvertRelativePathToFull(FPaths::GameSavedDir() + "users/sample.wmv");  
UFileMediaSource* fileSource = NewObject<UFileMediaSource>(this);
fileSource->FilePath = videoPath;

```

c). Create a UMediaPlayer and its UMediaSoundWave and UMediaTexture. Then Open file media source.

```
UMediaPlayer* mediaPlayer = NewObject<UMediaPlayer>(this);
mediaPlayer->SetLooping(true);

UMediaSoundWave* sound = NewObject<UMediaSoundWave>(this);
mediaPlayer->SetSoundWave(sound);

UMediaTexture* texture = NewObject<UMediaTexture>(this);
texture->UpdateResource();
mediaPlayer->SetVideoTexture(texture);

mediaPlayer->PlayOnOpen = true;

mediaPlayer->OpenSource(fileSource);

```

d). Dynamic create a material instance and set texture.

```
UMaterial* material = LoadObject<UMaterial>(NULL, TEXT("Material'/Game/Temp/M_Media.M_Media'"));

UMaterialInstanceDynamic* materialInstance = UMaterialInstanceDynamic::Create(material, this);

materialInstance->SetTextureParameterValue(FName("MediaTexture"), mediaPlayer->GetVideoTexture());

```

e). Set material to self and spawn a sound

```
SetMaterial(0, materialInstance);

UGameplayStatics::SpawnSoundAttached(mediaPlayer->GetSoundWave(), this, NAME_None, FVector::ZeroVector, FRotator::ZeroRotator,
	EAttachLocation::KeepRelativeOffset, true);

```

BTW, I’m using Windows 7 sp1 and UE 4.13.0

for replying.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0c62419a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0c62419a](https://forums.unrealengine.com/u/anonymous_user_0c62419a)\
**Post date:** [September 22, 2016, 8:36pm UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/7 "2016-09-22T20:36:55Z")

</div>

Thank you for submitting a bug report. I have reproduced this issue and logged a report for it here: [Unreal Engine Issues and Bug Tracker (UE-36321)](https://issues.unrealengine.com/issue/UE-36321)

You can track the report’s status as the issue is reviewed by our development staff.

Cheers,

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 22, 2016, 11:08pm UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/8 "2016-09-22T23:08:43Z")

</div>

I added a temporary fix for the upcoming 4.13.1 hotfix. In 4.14 this is not a problem anymore, because the MediaTexture works slightly different there. In the meantime, if you want to unblock yourself, add the following at the top of _UMediaTexture::Tick_:

```
    if (HasAnyFlags(RF_BeginDestroyed))
	{
		return false;
	}

```

for your minimal repro project!

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 22, 2016, 11:34pm UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/9 "2016-09-22T23:34:27Z")

</div>

By the way, you don’t have to create a FileMediaSource at run-time. You can simply use _UMediaPlayer::OpenUrl_ instead. It expects an URL scheme, so you have to prefix your path with _file://_, for example:

```
mediaPlayer->OpenUrl(FString(TEXT("file://")) + videoPath);

```

In 4.14 I also added the new _OpenFile_ method, which makes this a little more convenient:

```
mediaPlayer->OpenFile(videoPath);

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f60d77b1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f60d77b1](https://forums.unrealengine.com/u/anonymous_user_f60d77b1)\
**Post date:** [September 23, 2016, 5:39am UTC](https://forums.unrealengine.com/t/fatal-error-after-deleting-a-component-with-media-texture-a-frenderresource-was-deleted-without-being-released-first/371123/10 "2016-09-23T05:39:07Z")

</div>

a lot!
