fix(dock): ensure exception-safe reentrancy guard and symmetrical event cleanup

This commit is contained in:
2026-03-28 19:25:15 +09:00
parent 3f6de84387
commit de71043be3
2 changed files with 49 additions and 35 deletions

View File

@@ -110,50 +110,52 @@ public sealed partial class DockLayout
{
if (_isSyncingSizes) return;
bool isHorizontal = groupNode.Orientation == Orientation.Horizontal;
bool changed = false;
if (isHorizontal)
try
{
for (int i = 0; i < groupNode.Children.Count; i++)
bool isHorizontal = groupNode.Orientation == Orientation.Horizontal;
bool changed = false;
if (isHorizontal)
{
if (i < groupNode.Sizes.Count && i * 2 < grid.ColumnDefinitions.Count)
for (int i = 0; i < groupNode.Children.Count; i++)
{
var newWidth = grid.ColumnDefinitions[i * 2].Width;
if (!groupNode.Sizes[i].Equals(newWidth))
if (i < groupNode.Sizes.Count && i * 2 < grid.ColumnDefinitions.Count)
{
// Only sync if it's a star or pixel value (not Auto)
if (newWidth.IsStar || newWidth.IsAbsolute)
var newWidth = grid.ColumnDefinitions[i * 2].Width;
if (!groupNode.Sizes[i].Equals(newWidth))
{
_isSyncingSizes = true;
groupNode.Sizes[i] = newWidth;
changed = true;
// Only sync if it's a star or pixel value (not Auto)
if (newWidth.IsStar || newWidth.IsAbsolute)
{
_isSyncingSizes = true;
groupNode.Sizes[i] = newWidth;
changed = true;
}
}
}
}
}
else
{
for (int i = 0; i < groupNode.Children.Count; i++)
{
if (i < groupNode.Sizes.Count && i * 2 < grid.RowDefinitions.Count)
{
var newHeight = grid.RowDefinitions[i * 2].Height;
if (!groupNode.Sizes[i].Equals(newHeight))
{
if (newHeight.IsStar || newHeight.IsAbsolute)
{
_isSyncingSizes = true;
groupNode.Sizes[i] = newHeight;
changed = true;
}
}
}
}
}
}
else
{
for (int i = 0; i < groupNode.Children.Count; i++)
{
if (i < groupNode.Sizes.Count && i * 2 < grid.RowDefinitions.Count)
{
var newHeight = grid.RowDefinitions[i * 2].Height;
if (!groupNode.Sizes[i].Equals(newHeight))
{
if (newHeight.IsStar || newHeight.IsAbsolute)
{
_isSyncingSizes = true;
groupNode.Sizes[i] = newHeight;
changed = true;
}
}
}
}
}
if (changed)
finally
{
_isSyncingSizes = false;
}

View File

@@ -42,6 +42,13 @@ internal sealed partial class EngineEditorWindow : WindowEx
this.CenterOnScreen();
InitializeDockLayout();
this.Unloaded += OnUnloaded;
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
PART_DockLayout.TabTornOff -= OnTabTornOff;
}
private void InitializeDockLayout()
@@ -68,7 +75,12 @@ internal sealed partial class EngineEditorWindow : WindowEx
root.AddChild(rightGroup);
PART_DockLayout.Root = root;
PART_DockLayout.TabTornOff += (s, e) => App.CreateAndShowDockWindow(e.TabContent);
PART_DockLayout.TabTornOff += OnTabTornOff;
}
private void OnTabTornOff(object? sender, TabTornOffEventArgs e)
{
App.CreateAndShowDockWindow(e.TabContent);
}
private void MainGrid_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)