RetainerBox with size 0 child leaks LayerId

Hi Xiaohan Zhang,

Thank you for the report and minimal repro steps, which were extremely helpful. I was able to reproduce this behavior here in all 5.x versions, including the latest source build, and it does seem to be a bug.

I just filed an internal bug report about this, you should be able to track progress on it here once the engine devs mark it as public: UE-352267.

If you are able to make changes to the engine source code, you can fix this by changing the return value of the SRetainerWidget::OnPaint() function when the condition (PaintResult == EPaintRetainedContentResult::TextureSizeZero) is true, as you noted. However, instead of calling SCompoundWidget::OnPaint() like in the “TextureSizeTooBig” case (which would attempt to draw the RetainerBox contents in unretained mode), I’d recommend simply returning the same LayerId that was passed into the function:

else if (PaintResult == EPaintRetainedContentResult::TextureSizeZero)
{
	return LayerId;
}

The change above seems to resolve the issue on my end here. Please let me know if it works for you, and do not hesitate to ask if you need any further assistance.

Best regards,

Vitor