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 合并指标
 (30 天内没有已合并 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.

贡献者指南