List View Add Button Cause Recursively dispatching event

When pressing add element on List View when the whole visual element of the list view is full and it needs to expend its size, it throws many errors of

Recursively dispatching event UnityEngine.UIElements.PropertyChangedEvent from another event UnityEngine.UIElements.ChangeEvent`1[System.Single] (depth = 483)

Recursively dispatching event UnityEngine.UIElements.ChangeEvent1[System.Single] from another event UnityEngine.UIElements.ChangeEvent1[System.Single] (depth = 484)

Recursively dispatching event UnityEngine.UIElements.ChangeEvent1[System.Single] from another event UnityEngine.UIElements.ChangeEvent1[System.Single] (depth = 491)
Void Dispatch(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.BaseVisualElementPanel, UnityEngine.UIElements.DispatchMode)(:0)
Void SendEvent(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.DispatchMode)(:0)
Void SendEvent(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.DispatchMode)(:0)
Void set_value(Single)(:0)
Void set_value(Single)(:0)
Void set_value(Single)(:0)
Void OnSliderValueChange(UnityEngine.UIElements.ChangeEvent`1[System.Single])(:0)
Void Invoke(UnityEngine.UIElements.EventBase)(:0)
Void Invoke(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.BaseVisualElementPanel, UnityEngine.UIElements.VisualElement)(:0)
Void HandleEvent_BubbleUpCallbacks(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.BaseVisualElementPanel, UnityEngine.UIElements.VisualElement)(:0)
Void HandleEventAcrossPropagationPath(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.BaseVisualElementPanel, UnityEngine.UIElements.VisualElement, Boolean)(:0)
Void PropagateEvent(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.BaseVisualElementPanel, UnityEngine.UIElements.VisualElement, Boolean)(:0)
Void DefaultDispatch(UnityEngine.UIElements.EventBase, UnityEngine.UIElements.BaseVisualElementPanel)(:0)
Void Dispatch(UnityEngine.UIElements.BaseVisualElementPanel)(:0)

Untitled

And the code of the list is

        public void BindSubTasksArray(ListView list)
        {

            var elementInArray = _task.SubTasks;
            list.itemsSource = elementInArray;


            list.makeItem = () =>
            {
                return new SubTask();
            };

            list.bindItem = (element, e) =>
            {
                EditorApplication.delayCall += () =>
                {
                    var task = _task;
                    var baseElement = (SubTask)element;
                    baseElement.ConnectFields(task.SubTasks[e]);

                };
            };
            list.itemsAdded += (numbers) => _task.AddTaskElement(numbers);
            list.itemsRemoved += (numbers) => _task.RemoveTaskElement(numbers);
            list.virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight;
            list.reorderMode = ListViewReorderMode.Animated;
            list.reorderable = true;
            list.showAddRemoveFooter = true;

        }
        public class SubTask : VisualElement
        {
            public Toggle Toggle;
            public TextField TextField;

            public const string TOGGLE_CLASS = "sub-task_toggle";
            public const string TEXT_FIELD_CLASS = "sub-task_text-field";
            public const string VISUAL_CLASS = "sub-task_element";
            public SubTask()
            {
                AddToClassList(VISUAL_CLASS);
                Toggle = new Toggle();
                Toggle.AddToClassList(TOGGLE_CLASS);
                TextField = new TextField();
                TextField.AddToClassList(TEXT_FIELD_CLASS);
                Add(Toggle);
                Add(TextField);
            }
            public void ConnectFields(BoolenTask subTask)
            {
                Toggle.value = subTask.Finished;
                TextField.value = subTask.Name;

                TextField.RegisterValueChangedCallback((evt) => subTask.Name = evt.newValue);
                Toggle.RegisterValueChangedCallback((evt) => subTask.Finished = evt.newValue);
            }
        }

For workaround use fixed height.

tried that now, still causing the same errors and the same huge loading time.

As far I know, you don’t need code above. Here is mine.

            listView = new ListView();

            listView.makeItem = () =>
            {
                var liveVersus_VS = new LiveVersus();
                return liveVersus_VS;
            };

            listView.bindItem = (e, i) =>
            {
                var liveVersus = e as LiveVersus;

                if (liveVersus == null)
                    return;

                liveVersus.value = m_liveVersus[i];

            };

            listView.dataSource = m_liveVersus;
            listView.itemsSource = m_liveVersus;

It only need makeItem, bindItem, itemsSource, dataSource.

Also need to rebuild list view every Add and Remove.

Without adding manually to the array, the function “make item” wouldn’t add element to the array.
I have tried your suggestion; it is still causing the same error and also it throws an index was outside of bound because it is not making a new element without subscribing to add an element.

I apologize, it was reference from the runtime listView which don’t have add/remove button.

I have searched my editor listView which is multiColumnListView that I used. it’s indeed to write Add and Remove

      public List<EditorData> EditorDatas = new List<EditorData>();
       
       ... some other code...

        multiColumnListView.itemsAdded += (index) =>
        {
            foreach (var item in index)
            {
                EditorDatas.Insert(item, null);
            }
        };
        multiColumnListView.itemsRemoved += (index) =>
        {

            foreach (var item in index)
            {
                EditorDatas.RemoveAt(item);
            }
        };

Try comment this code.

Also, what’s purpose of EditorApplication.delayCall ? Try comment that.

Thank you anyway for trying to help,

The “EditorApplication.delayCall” is because the binding happens before the add item, so it throws an exception of index out of bound, and with that the binding happens after the adding item.

I tried to comment out all your suggestions; it didn’t change anything, still causing the same problem.
the problem always happens when trying to create the first element that is outside the bounds of the visual element, meaning the second and third the problem will not occur, only on the first element that is created to fit outside the bounds of the visual element.

And I have checked now, in Unity 2022, the problem doesn’t happen, so it is a bug in this specific Unity 6 and the updated Ui tool kit.

Ahh I see. Sorry can’t help you more.

You could report the bug. It will get check by unity QA. I have similiar problems in the past, then they fix it.

I encounter this bug as well. It seems to occur when a scroll bar is about to appear.

My workaround is to wrap the ListView with a ScrollView and remove the height constraint of the ListView itself, instead of relying on the ListView’s own scrollbar.

Hello! Could you please report a bug for this? We’ll take a look at it. Thank you!

Actually, you already resolved it.
https://unity3d.atlassian.net/servicedesk/customer/portal/2/IN-88612

Does the latest beta version solve this issue? I am currently on 6000.0.32f1