Skip to content

Commit

Permalink
Fix removing a control from a TableLayout before it has been initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Dec 6, 2023
1 parent ab88733 commit 4b6f3ef
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Mac/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Eto.WinForms/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Wpf/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Eto/Forms/Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,8 @@ internal set
/// </remarks>
public void Detach()
{
if (VisualParent != null)
VisualParent.Remove(this);
VisualParent?.Remove(this);
Parent?.Remove(this);
}

static readonly object IsAttached_Key = new object();
Expand Down

0 comments on commit 4b6f3ef

Please sign in to comment.