Fix error when using nested Visject Surface context during State Machines editing in Anim Graph
This commit is contained in:
@@ -33,6 +33,14 @@ namespace FlaxEditor.Surface.Undo
|
||||
|
||||
CaptureConnections(iB, out _inputBefore);
|
||||
CaptureConnections(oB, out _outputBefore);
|
||||
|
||||
#if BUILD_DEBUG
|
||||
// Validate handles
|
||||
if (_context.Get(_surface) != iB.ParentNode.Context)
|
||||
throw new System.Exception("Invalid ContextHandle");
|
||||
if (_input.Get(iB.ParentNode.Context) != iB || _output.Get(oB.ParentNode.Context) != oB)
|
||||
throw new System.Exception("Invalid BoxHandle");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void End()
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.Json;
|
||||
|
||||
namespace FlaxEditor.Surface.Undo
|
||||
{
|
||||
@@ -9,7 +11,7 @@ namespace FlaxEditor.Surface.Undo
|
||||
/// The helper structure for Surface context handle.
|
||||
/// </summary>
|
||||
[HideInEditor]
|
||||
public struct ContextHandle
|
||||
public struct ContextHandle : IEquatable<ContextHandle>
|
||||
{
|
||||
private readonly string[] _path;
|
||||
|
||||
@@ -42,6 +44,31 @@ namespace FlaxEditor.Surface.Undo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContextHandle"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="child">The child context provider.</param>
|
||||
public ContextHandle(ISurfaceContext child)
|
||||
{
|
||||
if (child == null)
|
||||
throw new ArgumentNullException();
|
||||
VisjectSurfaceContext parent = child.ParentContext;
|
||||
VisjectSurfaceContext context = parent;
|
||||
int count = 1;
|
||||
while (parent != null)
|
||||
{
|
||||
count++;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
_path = new string[count];
|
||||
_path[0] = child.SurfaceName;
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
_path[i] = context.Context.SurfaceName;
|
||||
context = context.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context.
|
||||
/// </summary>
|
||||
@@ -69,5 +96,46 @@ namespace FlaxEditor.Surface.Undo
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(ContextHandle other)
|
||||
{
|
||||
return JsonSerializer.ValueEquals(_path, other._path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is ContextHandle other && Equals(other);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
if (_path != null)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
for (var i = 0; i < _path.Length; i++)
|
||||
{
|
||||
var item = _path[i];
|
||||
hash = hash * 23 + (item != null ? item.GetHashCode() : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (_path == null)
|
||||
return string.Empty;
|
||||
for (int i = _path.Length - 1; i >= 0; i--)
|
||||
sb.Append(_path[i]).Append('/');
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user