|
Post by ohthepain on Jan 5, 2023 17:12:27 GMT
I have a bug where multiple of the cells are displaying the same item. I think it may be because of multithreading.
The docs say "If you need to use coroutines in your cell view setup, you will need to move your cell setup from the GetCellView to the cellVisibilityChanged handler. "
But how do I connect cellVisibilityChanged? I can't find any reference to it anywhere, not in the code base, docs or any google search.
|
|
|
Post by echo17 on Jan 5, 2023 18:29:06 GMT
The CellViewVisibility delegate is the first one in the EnhancedScroller.cs code: Check out Demo #5 that shows one way to handle coroutines and loading data for the cells. You'll see in the Controller.cs script Start method these lines: // set the scroller's cell view visbility changed delegate to a method in this controller scroller.cellViewVisibilityChanged = CellViewVisibilityChanged; scroller.cellViewWillRecycle = CellViewWillRecycle;
These comments in the GetCellView method: // In this example, we do not set the data here since the cell is not visibile yet. Use a coroutine // before the cell is visibile will result in errors, so we defer loading until the cell has // become visible. We can trap this in the cellViewVisibilityChanged delegate handled below
and this code for the visibility change: /// <summary> /// This handler will be called any time a cell view is shown or hidden /// </summary> /// <param name="cellView">The cell view that was shown or hidden</param> private void CellViewVisibilityChanged(EnhancedScrollerCellView cellView) { // cast the cell view to our custom view CellView view = cellView as CellView;
// if the cell is active, we set its data, // otherwise we will clear the image back to // its default state
if (cellView.active) view.SetData(_data[cellView.dataIndex]); else view.ClearImage(); }
I would recommend starting with this demo to understand coroutines and cell views and build from there.
|
|
|
Post by ohthepain on Jan 11, 2023 13:40:52 GMT
Now I am starting to wonder if I'm barking up the wrong tree. Is this the type of bug you expect to see from threading issues? I am seeing 6 cells but there are only 5 data.
The issue occurs when we are auto-scrolling while recycling cells.
The items are - Gold, silver ring, stick, shoes, recruits
Gold, silver ring, stick, shoes appear. Then when gold disappears, each item is replaced by the previous item. I.e, - silver ring becomes gold, - stick becomes silver ring - shoes become stick - recruits appear and replace shoes
The game thinks there is 5 cells when there are really only 4.
Unfortunately I can't rebuild this system this just to fix the bug this is a new bug that has popped up since updating to Unity 2021 with its multithreading
|
|
|
Post by echo17 on Jan 11, 2023 23:02:10 GMT
I'm not sure what your issue might be. I will need to see a working example of the problem to help you diagnose. Please see this FAQ for more information: link
|
|