From 4b6f3efb6aec0e21a6e48f4caa0b5256f476d7f2 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Wed, 6 Dec 2023 12:09:13 -0800 Subject: [PATCH] Fix removing a control from a TableLayout before it has been initialized --- src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs | 3 +++ src/Eto.Mac/Forms/TableLayoutHandler.cs | 2 ++ src/Eto.WinForms/Forms/TableLayoutHandler.cs | 3 ++- src/Eto.Wpf/Forms/TableLayoutHandler.cs | 2 ++ src/Eto/Forms/Controls/Control.cs | 4 ++-- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs b/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs index cc9747f975..39701a4a64 100644 --- a/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs +++ b/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs @@ -152,6 +152,9 @@ bool Attach(Control child, int x, int y) public void Remove(Control child) { + if (controls == null) + return; + for (int y = 0; y < controls.GetLength(0); y++) { for (int x = 0; x < controls.GetLength(1); x++) diff --git a/src/Eto.Mac/Forms/TableLayoutHandler.cs b/src/Eto.Mac/Forms/TableLayoutHandler.cs index cfb2b0bd7a..8dd3c01ef5 100644 --- a/src/Eto.Mac/Forms/TableLayoutHandler.cs +++ b/src/Eto.Mac/Forms/TableLayoutHandler.cs @@ -347,6 +347,8 @@ public void Move(Control child, int x, int y) public void Remove(Control child) { + if (views == null) + return; for (int y = 0; y < views.GetLength(0); y++) for (int x = 0; x < views.GetLength(1); x++) { diff --git a/src/Eto.WinForms/Forms/TableLayoutHandler.cs b/src/Eto.WinForms/Forms/TableLayoutHandler.cs index 02caa532d5..a1ee2f0b50 100644 --- a/src/Eto.WinForms/Forms/TableLayoutHandler.cs +++ b/src/Eto.WinForms/Forms/TableLayoutHandler.cs @@ -272,7 +272,8 @@ public void Remove(Control child) if (childControl.Parent == Control) { var pos = Control.GetCellPosition(childControl); - views[pos.Column, pos.Row] = null; + if (views != null) + views[pos.Column, pos.Row] = null; childControl.Parent = null; SetEmptyCell(pos.Column, pos.Row); } diff --git a/src/Eto.Wpf/Forms/TableLayoutHandler.cs b/src/Eto.Wpf/Forms/TableLayoutHandler.cs index ad86eb2fb1..ed83fddd21 100755 --- a/src/Eto.Wpf/Forms/TableLayoutHandler.cs +++ b/src/Eto.Wpf/Forms/TableLayoutHandler.cs @@ -361,6 +361,8 @@ public Padding Padding void Remove(int x, int y) { + if (controls == null) + return; var control = controls[x, y]; if (control != null) { diff --git a/src/Eto/Forms/Controls/Control.cs b/src/Eto/Forms/Controls/Control.cs index 7318db361a..004f76b6f4 100755 --- a/src/Eto/Forms/Controls/Control.cs +++ b/src/Eto/Forms/Controls/Control.cs @@ -991,8 +991,8 @@ public new Container FindParent(string id) /// public void Detach() { - if (VisualParent != null) - VisualParent.Remove(this); + VisualParent?.Remove(this); + Parent?.Remove(this); } static readonly object IsAttached_Key = new object();