Fix memory leak on material instances when updating layout of Text Render
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user