Cannot Queue Expression Cache - Garbage Collection

Hey Guys, I have a problem where my game crash when I call the SetImage() function from SImage.h as seen at line 11 below in the code snippet. The error is specifically. “Cannot queue the expression cache when it is about to be deleted.” MaterialShared.cpp [Line 2410} I believe this is pending GC? can anyone enlighten me?

My Slate widget inherits from SCompoundWidget, the error only ocurs when I call setimage()

Thank you

header.h


TSharedPtr<class SImage> PawnViewImage;

Source.cpp


1. UMaterialInterface* PawnViewMatInst = LoadObject<UMaterialInterface>(NULL, TEXT("MaterialInstanceConstant'/Game/Blueprints/UserWidgets/Minimap/Material/EnemyViewMat_Inst.EnemyViewMat_Inst'"));
2.
3. UMaterialInstanceDynamic* PawnViewMatDynamic = UMaterialInstanceDynamic::Create(EnemyViewMatInst, nullptr);
4.
5. FSlateBrush* PawnViewBrush = new FSlateBrush();
6.
7. PawnViewBrush->ImageSize = FVector2D(210.f, 210.f);
8. PawnViewBrush->DrawAs = ESlateBrushDrawType::Image;
9.
10.PawnViewBrush->SetResourceObject(EnemyViewMatDynamic);
11.PawnViewImage->SetImage(EnemyViewBrush);
12.PawnViewImage->SetColorAndOpacity(FLinearColor(0.3f, 1.f, 0.32f, 0.4f));

ChildSlot


+ SOverlay::Slot()
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SAssignNew(PawnViewImage, SImage)
]


MaterialShared.cpp snippet


void FMaterialRenderProxy::InvalidateUniformExpressionCache(bool bRecreateUniformBuffer)
{
check(IsInRenderingThread());

[Line 2410]
if (HasVirtualTextureCallbacks)
{
GetRendererModule().RemoveAllVirtualTextureProducerDestroyedCallbacks(this);
HasVirtualTextureCallbacks = false;
}

Did you ever solve this? I’m having this problem now from just deleting components with dynamic material instances.

Since this is the only result for this on the entirety of the interwebs, I’ll give what I found and hope it helps some future traveler…

EDIT: I posted a long paragraph here about how I had to check my pointers in really weird ways to solve this issue, but the real solution is much simpler: I wasn’t marking my UMaterialInstanceDynamic pointers as UPROPERTY(), so they were getting unexpectedly picked up by garbage collection. Add UPROPERTY() to your UObjects if you don’t want them suicided.

2 Likes

Not sure if it will solve, since this crash does not happen all the time with me, but i’ll give it a try. For sure UPROPERTY() sometimes fix GC and pointers issues. Thanks!