dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

[Windows] Nullpointer from ListView.ScrollTo #24347

Open Larhei opened 3 weeks ago

Larhei commented 3 weeks ago

Description

When adding an item to an Observable Collection in my ViewModel and than try to scroll to it, i´m getting a Nullpointer from the ListViewRenderer from time to time. To illustrate the issue i wrote some code that does not make sense in real world but it illustrates the issue. Looks like a race condition to me. The item is in the Itemssource on maui side... but not in the native side of things. But this is just a guess. On Android it is not crashing, but logcat is giving also nullpointer logs.

Steps to Reproduce

  1. Checkout Repos on Windows
  2. Run on Windows

Link to public reproduction project repository

https://github.com/Larhei/Maui-Issues/tree/main/ScrollToNullPointer

Version with bug

8.0.80 SR8

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

net8.0-windows10.0.19041.0

Did you find any workaround?

Addind a delay between adding to the collection and call to ScrollTo stops the Nullpointer from happening. But in case UI-Thread is busy this could lead again to this nullpointer i guess.

Relevant log output

at Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer.<>c__DisplayClass42_1.<<ScrollTo>b__2>d.MoveNext()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()
github-actions[bot] commented 3 weeks ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

jaosnz-rep commented 3 weeks ago

I can repro this issue at Windows platform on the latest 17.12.0 Preview 1.0(8.0.80 & 8.0.72).