LoopScrollRect
LoopScrollRect copied to clipboard
OnRectTransformDimensionsChange()->UpdateBounds(true)
在提交https://github.com/qiankanglai/LoopScrollRect/commit/629112ce5cb5afcc9214753e830597e961042013中,将UpdateBounds()放在OnRectTransformDimensionsChange()方法中调用,我将这次提交合并到我们的项目中,发生了严重bug。原因在于,UpdateBounds()最终会引起ClearTempPool()->prefabSource.ReturnObject()的调用,而prefabSource`在没有初始化时为空,具体错误日志如下:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UI.LoopScrollRect.ClearTempPool () (at Assets/Plugins/CustomUGUI/LoopScrollRect/Runtime/LoopScrollRect.cs:61)
UnityEngine.UI.LoopVerticalScrollRect.UpdateItems (UnityEngine.Bounds& viewBounds, UnityEngine.Bounds& contentBounds) (at Assets/Plugins/CustomUGUI/LoopScrollRect/Runtime/LoopVerticalScrollRect.cs:178)
UnityEngine.UI.LoopScrollRectBase.UpdateBounds (System.Boolean updateItems) (at Assets/Plugins/CustomUGUI/LoopScrollRect/Runtime/LoopScrollRectBase.cs:2181)
UnityEngine.UI.LoopScrollRectBase.OnRectTransformDimensionsChange () (at Assets/Plugins/CustomUGUI/LoopScrollRect/Runtime/LoopScrollRectBase.cs:1988)
OnRectTransformDimensionsChange()的调用无法预测,它甚至能在修改一个非激活的游戏物体时触发,是否考虑加入保护机制,或者回滚这次提交。