AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.88k stars 2.24k forks source link

TreeView crashes when switching UserControl #3826

Open RunOnceEx opened 4 years ago

RunOnceEx commented 4 years ago

When I open the Treeview subkey and switch to another UserControl, a crash occurs when I switch back


Avalonia.AvaloniaInternalException: Was attached to logical tree but cannot find root.
  at at Avalonia.StyledElement.Avalonia.Controls.ISetLogicalParent.SetParent(ILogical parent)
  at at Avalonia.Controls.Primitives.TemplatedControl.ApplyTemplate()
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.StackPanel.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.Presenters.ItemVirtualizer.MeasureOverride(Size availableSize)
  at at Avalonia.Controls.Presenters.ItemsPresenter.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.StackPanel.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.StackPanel.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.Presenters.ItemVirtualizer.MeasureOverride(Size availableSize)
  at at Avalonia.Controls.Presenters.ItemsPresenter.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.Presenters.ScrollContentPresenter.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
  at at Avalonia.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
  at at Avalonia.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
  at at Avalonia.Controls.Grid.MeasureOverride(Size constraint)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding)
  at at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding, Thickness borderThickness)
  at at Avalonia.Controls.Border.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
  at at Avalonia.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
  at at Avalonia.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
  at at Avalonia.Controls.Grid.MeasureOverride(Size constraint)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding)
  at at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding, Thickness borderThickness)
  at at Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding)
  at at Avalonia.Layout.LayoutHelper.MeasureChild(ILayoutable control, Size availableSize, Thickness padding, Thickness borderThickness)
  at at Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Size availableSize)
  at at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
  at at Avalonia.Layout.Layoutable.Measure(Size availableSize)
  at at Avalonia.Layout.LayoutManager.Measure(ILayoutable control)
  at at Avalonia.Layout.LayoutManager.ExecuteMeasurePass()
  at at Avalonia.Layout.LayoutManager.ExecuteLayoutPass()
  at at Avalonia.Controls.Presenters.ItemVirtualizerSimple.ScrollIntoView(Int32 index)
  at at Avalonia.Controls.Presenters.ItemVirtualizerSimple.ScrollIntoView(Object item)
  at at Avalonia.Controls.Presenters.ItemsPresenter.ScrollIntoView(Object item)
  at at Avalonia.Controls.Primitives.SelectingItemsControl.ScrollIntoView(Object item)
  at at Avalonia.Controls.Primitives.SelectingItemsControl.UpdateSelectedItem(Int32 index, Boolean clear)
  at at Avalonia.Controls.Primitives.SelectingItemsControl.UpdateSelection(Int32 index, Boolean select, Boolean rangeModifier, Boolean toggleModifier, Boolean rightButton)
  at at Avalonia.Controls.Primitives.SelectingItemsControl.UpdateSelection(IControl container, Boolean select, Boolean rangeModifier, Boolean toggleModifier, Boolean rightButton)
  at at Avalonia.Controls.Primitives.SelectingItemsControl.UpdateSelectionFromEventSource(IInteractive eventSource, Boolean select, Boolean rangeModifier, Boolean toggleModifier, Boolean rightButton)
  at at Avalonia.Controls.ListBox.OnPointerPressed(PointerPressedEventArgs e)
  at at Avalonia.Input.InputElement.<>c.<.cctor>b__25_8(InputElement x, PointerPressedEventArgs e)
  at at Avalonia.Interactivity.RoutedEvent`1.<>c__DisplayClass2_0`1.<AddClassHandler>g__Adapter|0(Object sender, RoutedEventArgs e)
  at at Avalonia.Interactivity.RoutedEvent.<>c__DisplayClass21_0.<AddClassHandler>b__0(ValueTuple`2 args)
  at System.Reactive.AnonymousObserver`1.OnNextCore(T value) in /_/Rx.NET/Source/src/System.Reactive/AnonymousObserver.cs:67
  at System.Reactive.ObserverBase`1.OnNext(T value) in /_/Rx.NET/Source/src/System.Reactive/ObserverBase.cs:36
  at System.Reactive.Subjects.Subject`1.OnNext(T value) in /_/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs:148
  at at Avalonia.Interactivity.RoutedEvent.InvokeRaised(Object sender, RoutedEventArgs e)
  at at Avalonia.Interactivity.Interactive.RaiseEventImpl(RoutedEventArgs e)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.HierarchyTraverser`2.Traverse(IInteractive target)
  at at Avalonia.Interactivity.Interactive.BubbleEvent(RoutedEventArgs e)
  at at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e)
  at at Avalonia.Input.MouseDevice.MouseDown(IMouseDevice device, UInt64 timestamp, IInputElement root, Point p, PointerPointProperties properties, KeyModifiers inputModifiers)
  at at Avalonia.Input.MouseDevice.ProcessRawEvent(RawPointerEventArgs e)
  at at Avalonia.Input.MouseDevice.ProcessRawEvent(RawInputEventArgs e)
  at at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs e)
  at at Avalonia.Controls.TopLevel.HandleInput(RawInputEventArgs e)
  at at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
  at at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
  at at Avalonia.Win32.Win32Platform.RunLoop(CancellationToken cancellationToken)
  at at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
  at at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
  at at Avalonia.Controls.AppBuilderBase`1.Start[TMainWindow](Func`1 dataContextProvider)
  at Test.Program.Main(String[] args) in F:\DevProject\TestDev\Test\Program.cs:29
danwalmsley commented 4 years ago

@RunOnceEx we will need a minimal repro project to understand what exactly your doing here. Can you upload a zip with some code to reproduce?

RunOnceEx commented 4 years ago

@RunOnceEx we will need a minimal repro project to understand what exactly your doing here. Can you upload a zip with some code to reproduce? AvaloniaTreeViewBugTest.zip First of all, thank you for taking the time to answer my question. A small Demo is written here. Switching the UserControl after opening the TreeView will cause a crash.