Fix memory leak on material instances when updating layout of Text Render

This commit is contained in:
Wojtek Figat
2025-07-04 12:21:25 +02:00
parent 2dd34b288c
commit 48c6339ebb

View File

@@ -190,6 +190,10 @@ void TextRender::UpdateLayout()
_buffersDirty = true;
// Init draw chunks data
Array<MaterialInstance*, InlinedAllocation<8>> materials;
materials.Resize(_drawChunks.Count());
for (int32 i = 0; i < materials.Count(); i++)
materials[i] = _drawChunks[i].Material;
DrawChunk drawChunk;
drawChunk.Actor = this;
drawChunk.StartIndex = 0;
@@ -242,10 +246,12 @@ void TextRender::UpdateLayout()
}
// Setup material
drawChunk.Material = Content::CreateVirtualAsset<MaterialInstance>();
if (_drawChunks.Count() < materials.Count())
drawChunk.Material = materials[_drawChunks.Count()];
else
drawChunk.Material = Content::CreateVirtualAsset<MaterialInstance>();
drawChunk.Material->SetBaseMaterial(Material.Get());
for (auto& param : drawChunk.Material->Params)
param.SetIsOverride(false);
drawChunk.Material->ResetParameters();
// Set the font parameter
static StringView FontParamName = TEXT("Font");