xamarin/Xamarin.Forms

[Bug] Crash in Layout. ResolveLayoutChanges

開放

#9,062 建立於 2020年1月2日

 (5 則留言) (1 個反應) (0 位負責人)C# (1,926 個分叉)batch import
help wantedin-progresss/unverifiedt/bug :bug:up-for-grabs

倉庫指標

星標
 (5,644 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Description

Crash in Layout.ResolveLayoutChanges: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

Steps to Reproduce

Steps are unknown yet, we are trying to reliably recreate it. We are seeing the crashes through AppCenter and are getting plenty of them across different Android devices.

I have a console app that replicates the underlying bug: https://gist.github.com/slang25/f26349340f74300d67f7c552cb2b2493

Expected Behavior

No crash.

Actual Behavior

In a StackLayout, in Layout.OnChildMeasureInvalidated, it should queue up layout update operations in s_resolutionList for Layout.ResolveLayoutChanges to process.

Layout.ResolveLayoutChanges "copies" s_resolutionList, however it copies the reference, this means that if GetElementDepth is slow during OnChildMeasureInvalidated, it could have dereferenced the old list. By adding an item to the old s_resolutionList reference, it risks this exception for occurring.

Other Information

Console app that replicates basic non-thread-safe underlying issue can be found here: https://gist.github.com/slang25/f26349340f74300d67f7c552cb2b2493

There are a few quick fixes, including this: https://github.com/xamarin/Xamarin.Forms/compare/xamarin:master...slang25:fix-layout-crash?expand=1

But I'd like to work on a more complete fix.

貢獻者指南