Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug ListView Bind ArraySize+Scroll Bug

Discussion in 'UI Toolkit' started by Lieene-Guo, Apr 24, 2021.

  1. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    In
    Code (CSharp):
    1. ListView:OnScroll(float offset)
    this part (line:1460)
    Code (CSharp):
    1. for (var i = 0; i < m_Pool.Count; i++)
    2. {
    3.     int index = i + m_FirstVisibleIndex;
    4.     if (index < itemsSource.Count)
    5.         Setup(m_Pool[i], index);
    6.     else
    7.         m_Pool[i].element.style.display = DisplayStyle.None;
    8. }
    m_FirstVisibleIndex could be -1 when SerializedProperty:ArraySize is bound.
    and the ListViewBinding will try to bind ArrayElementAt(-1) and result in an index exception.
    Using the first element of ListView::ScorllView is a bad idea.
    We may let ListView to have a contentContainer
    so we can put size field, add/remove item button and info label in it.
     
    oscarAbraham likes this.
  2. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    Also when reorder is enabled.
    when dragging ListView size item to the bottom of the list an index exception will be throwing.
    and It is also because bind-size-as-a-List-Item design.
     
    oscarAbraham likes this.
  3. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    It seems there should be more check related to m_FirstVisibleIndex in both the OnScroll and when reordering.

    Can you file a bug using Help->Report a Bug in unity?