Unity-Technologies / com.unity.uiwidgets

UIWidgets is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps.
https://unity.cn/uiwidgets
626 stars 78 forks source link

fix oom bug #350

Closed zhuxingwei closed 2 years ago

zhuxingwei commented 2 years ago

In this PR we aims to fix a potential OOM bug observed on android/ios devices.

The bug is caused by the fact that: in one frame, a CompositorContext is used to preroll and the paint the layer tree which holds a rasterize cache to boost the performance. Generally, it will first generate the cache in the preroll call and then at the end of the frame, it will release unused cache when the unique pointer of compositor_frame is released and the method CompositorContext::ScopedFrame::~ScopedFrame() is called. Note that since the cache holds shared memory between gpu and cpu, it is important to keep a valid gpu context while doing the release job.

However, in one PR I made before, it mistakenly clears the gpu context before the compositor_frame is released (which happens when the whole function is finished and the specific unique pointer is out of scope). As the result, the gpu side memory might be unable to be released properly.

To fix this issue, we just guarantee that we clear the gpu context only after the compositor_frame is released