Fixes to TextPic to make sure images are culled properly.

pull/413/head
Brad Nelson 2019-03-02 00:23:06 +00:00
parent d6bb530fee
commit 561cc87cf0
1 changed files with 9 additions and 7 deletions

View File

@ -180,7 +180,7 @@ namespace UnityEngine.UI.Extensions {
} }
else { else {
// If there are no matches, remove the images from the pool // If there are no matches, remove the images from the pool
for (int i = 0; i < m_ImagesPool.Count; i++) { for (int i = m_ImagesPool.Count - 1; i > 0; i--) {
if (m_ImagesPool[i]) { if (m_ImagesPool[i]) {
if (!culled_ImagesPool.Contains(m_ImagesPool[i].gameObject)) { if (!culled_ImagesPool.Contains(m_ImagesPool[i].gameObject)) {
culled_ImagesPool.Add(m_ImagesPool[i].gameObject); culled_ImagesPool.Add(m_ImagesPool[i].gameObject);
@ -191,7 +191,8 @@ namespace UnityEngine.UI.Extensions {
} }
// Remove any images that are not being used // Remove any images that are not being used
for (var i = matches.Count; i < m_ImagesPool.Count; i++) { for (int i = m_ImagesPool.Count - 1; i >= matches.Count; i--) {
if (i >= 0 && m_ImagesPool.Count > 0) {
if (m_ImagesPool[i]) { if (m_ImagesPool[i]) {
if (!culled_ImagesPool.Contains(m_ImagesPool[i].gameObject)) { if (!culled_ImagesPool.Contains(m_ImagesPool[i].gameObject)) {
culled_ImagesPool.Add(m_ImagesPool[i].gameObject); culled_ImagesPool.Add(m_ImagesPool[i].gameObject);
@ -199,6 +200,7 @@ namespace UnityEngine.UI.Extensions {
} }
} }
} }
}
// Clear the images when it is safe to do so // Clear the images when it is safe to do so
if (culled_ImagesPool.Count > 0) { if (culled_ImagesPool.Count > 0) {
@ -514,7 +516,7 @@ namespace UnityEngine.UI.Extensions {
// Disable images on TextPic disable // Disable images on TextPic disable
if (m_ImagesPool.Count >= 1) { if (m_ImagesPool.Count >= 1) {
for (int i = 0; i < m_ImagesPool.Count; i++) { for (int i = 0; i < m_ImagesPool.Count; i++) {
if(m_ImagesPool[i] != null) { if (m_ImagesPool[i] != null) {
m_ImagesPool[i].enabled = false; m_ImagesPool[i].enabled = false;
} }
} }