Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for crash while drawing Point manipulator (gizmo) when LibG fails to load #10148

Merged
merged 7 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/DynamoCoreWpf/Rendering/HelixRenderPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public HelixRenderPackage()
/// Set the transform that is applied to all geometry in the renderPackage.
/// </summary>
/// <param name="transform"></param>
// TODO: Unused method. Adds unnecessary dependency on ProtoGeometry. Remove in 3.0
[Obsolete("This method will be removed in 3.0. Use SetTransform(double[] matrix) instead.")]
public void SetTransform(Autodesk.DesignScript.Geometry.CoordinateSystem transform)
{
var xaxis = transform.XAxis;
Expand All @@ -95,12 +97,15 @@ public void SetTransform(Autodesk.DesignScript.Geometry.CoordinateSystem transfo
this.Transform = csAsMat.ToArray();
}


/// <summary>
/// Set the transform that is applied to all geometry in the renderPackage
/// by computing the matrix that transforms between from and to.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
// TODO: Unused method. Adds unnecessary dependency on ProtoGeometry. Remove in 3.0
[Obsolete("This method will be removed in 3.0.")]
public void SetTransform(Autodesk.DesignScript.Geometry.CoordinateSystem from, Autodesk.DesignScript.Geometry.CoordinateSystem to)
{
var inverse = from.Inverse();
Expand Down Expand Up @@ -149,8 +154,14 @@ public void SetTransform(double m11, double m12, double m13, double m14,

/// <summary>
/// Set the transform as a double array, this transform is applied to all geometry in the renderPackage.
/// NOTE: this matrix is assumed to be in row vector form, and will be transformed into the neccesary form
/// for helix
/// This matrix should be laid out as follows in row vector order:
/// [Xx,Xy,Xz, 0,
/// Yx, Yy, Yz, 0,
/// Zx, Zy, Zz, 0,
/// offsetX, offsetY, offsetZ, W]
/// NOTE: This method should transform the matrix from row vector order to whatever form is needed by the implementation.
/// When converting from ProtoGeometry CoordinateSystem form to input matrix, set the first row to the X axis of the CS,
/// the second row to the Y axis of the CS, the third row to the Z axis of the CS, and the last row to the CS origin, where W = 1.
/// </summary>
/// <param name="matrix"></param>
public void SetTransform(double[] matrix)
Expand Down
57 changes: 51 additions & 6 deletions src/DynamoManipulation/NodeManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ internal IRenderPackageFactory RenderPackageFactory
}

internal Point3D? CameraPosition { get; private set; }

// This is null for each new manipulator that is initialized.
private bool? isValidNode;

/// <summary>
/// This property is true if the cached value of the manipulator node is non-null.
/// It caches its value so that it doesn't have to repeatedly query the node value.
/// NOTE: There could be edge cases where the node value could become null while the
/// manipulator is being moved, etc. These cases will not be caught and the boolean
/// value returned would be true even though it should change to false. This case could
/// lead to a potential crash and is yet to be addressed.
/// </summary>
private bool IsValidNode
{
get
{
if (isValidNode == null)
{
isValidNode = !IsNodeNull(Node.CachedValue);
}

return (bool) isValidNode;
}

}

#endregion

Expand Down Expand Up @@ -154,7 +179,8 @@ protected virtual void Dispose(bool disposing)
/// <param name="mouseButtonEventArgs"></param>
protected virtual void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{

if (!IsValidNode) return;

active = UpdatePosition();

GizmoInAction = null; //Reset Drag.
Expand Down Expand Up @@ -430,7 +456,7 @@ private RenderPackageCache GenerateRenderPackages()

// This check is required as for some reason LibG fails to load, geometry nodes are null
// and we must return immediately before proceeding with further calls to ProtoGeometry
if (IsNodeValueNull()) return packages;
if (IsNodeNull(Node.CachedValue)) return packages;

AssignInputNodes();

Expand Down Expand Up @@ -551,28 +577,47 @@ public RenderPackageCache BuildRenderPackage()
return packages;
}

#endregion

/// <summary>
/// Checks if manipulator is enabled or not. Manipulator is enabled
/// only if node is not frozen or not setup as partially applied function
/// only if node is not frozen, its preview visible and value non-null.
/// </summary>
/// <returns>True if enabled and can be manipulated.</returns>
public bool IsEnabled()
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
{
if (Node.IsFrozen || !Node.IsVisible) return false;

if (IsNodeValueNull())
if (!IsValidNode)
{
return false;
}

return active;
}

// TODO: Remove in 3.0
[Obsolete("This method will be removed in 3.0 and will no longer be available as a public API.")]
public bool IsNodeValueNull()
{
return Node.CachedValue == null || Node.CachedValue.IsNull;
return IsNodeNull(Node.CachedValue);
}

private static bool IsNodeNull(MirrorData data)
{
if (data == null || data.IsNull) return true;

if (data.IsCollection)
{
var elements = data.GetElements();
foreach (var element in elements)
{
if (IsNodeNull(element)) return true;
}
}

return false;
}
#endregion
}


Expand Down
4 changes: 3 additions & 1 deletion src/NodeServices/GraphicsDataInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ void SetTransform(double m11, double m12, double m13, double m14,
/// Yx, Yy, Yz, 0,
/// Zx, Zy, Zz, 0,
/// offsetX, offsetY, offsetZ, W]
///NOTE: This method should transform the matrix from row vector order to whatever form is needed by the implementation.
/// NOTE: This method should transform the matrix from row vector order to whatever form is needed by the implementation.
/// When converting from ProtoGeometry CoordinateSystem form to input matrix, set the first row to the X axis of the CS,
/// the second row to the Y axis of the CS, the third row to the Z axis of the CS, and the last row to the CS origin, where W = 1.
/// </summary>
/// <param name="matrix"></param>
void SetTransform(double[] matrix);
Expand Down