Crash when changing a texture after stopping a preview in the material editor

Effectively, what it appears to be is that the preview material isn’t cleaned up and is left in a state of having an stale material graph, thus when an actual dependency has changed it’s unable to resolve the internal texture and instead dies.

Steps to Reproduce

  1. Create a new material
  2. Add a texture node
  3. Plug it out to the base color
  4. Create a constant node
  5. Feed that into a debug scalar values
  6. Right click the node and select start previewing node
  7. Stop previewing node
  8. Modify the original texture in anyway, with the material editor still open
  9. Observe crash

[Image Removed]

[2025.08.29-09.57.48:732][ 69]LogMaterial: Error: Compiler->Texture() failed to find texture 'DebugNumberStrip' in referenced list of size '0':
[2025.08.29-09.57.48:732][ 69]LogOutputDevice: Warning: 

checkf(TextureReferenceIndex != INDEX_NONE, TEXT("Material expression called Compiler->Texture() without implementing UMaterialExpression::GetReferencedTexture properly"));

Locally I have a fix in `void FMaterialEditor::SetPreviewExpression(UMaterialExpression* NewPreviewExpression)`.

		if (ExpressionPreviewMaterial)
		{
			ExpressionPreviewMaterial->GetExpressionCollection().Empty();
		}

to

		if (ExpressionPreviewMaterial)
		{
			ExpressionPreviewMaterial = nullptr;
		}

Effectively blasting the preview material when it’s no longer used, seems needless to keep it alive regardless.

Hi Alister,

Thank you for reporting this crash. I was able to reproduce it here all the way from at least UE 4.27 with the following simplified steps:

1. Create and edit a new material

2. Place a Texture Sample node

3. On the Details Panel for the Texture Sample node, select any texture to sample from

4. Start previewing the Texture Sample Node (e.g. “Preview” button or “Right-click -- Start Previewing Node”)

5. Stop previewing the Texture Sample Node (e.g. “Preview” button or “Right-click -- Start Previewing Node”)

6. Open the chosen texture asset for editing (e.g. through the Content Browser or the Details Panel for the Texture Sample node)

Repro notes:

- Connecting or not the Texture Sample node to the Material Attributes node does not affect the crash

- On steps 4 and 5, the previewed node can be any one that needs the result of the Texture Sample node

- On step 6, the crash happens when trying to open any texture asset that is present in the Material Graph, regardless of whether it is actually connected and used by the previewed node or by the full material.

- On step 6, if the texture asset was already open, the crash can also be triggered by going to it and changing one of the following properties:

- LODGroup

- CompressionSettings

- CompressionQuality

- AddressX (X-axis Tiling Method)

- AddressY (Y-axis Tiling Method)

- Filter

- Srgb

- VirtualTextureStreaming

I just filed an internal bug report about this issue, here’s the bug tracker link: UE-318809. You should be able to access it once the engine devs mark it as public.

About your solution, it does seem appropriate, so I included it as a suggestion in the bug report.

Please let me know if you need anything further.

Best regards,

Vitor