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 1 commit
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
2 changes: 1 addition & 1 deletion src/DynamoManipulation/Gizmo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internal Gizmo(NodeManipulator manipulator)

private void Redraw()
{
if (manipulator.Enabled)
if (manipulator.IsEnabled())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this happens whenever the camera is moved?

Copy link
Contributor Author

@aparajit-pratap aparajit-pratap Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call takes place for every camera changed event and there's another call to IsEnabled() in MouseMove(). Since the isValidNode field is cached, however, these methods will not recursively inspect the node's cached value each time.

{
BackgroundPreviewViewModel.AddGeometryForRenderPackages(GetDrawables());
}
Expand Down
40 changes: 22 additions & 18 deletions src/DynamoManipulation/NodeManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,27 @@ internal IRenderPackageFactory RenderPackageFactory

internal Point3D? CameraPosition { get; private set; }

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

/// <summary>
/// A manipulator is enabled when its corresponding node is
/// not frozen, its geometry preview is visible and its cached value is valid.
/// 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>
public bool Enabled
private bool IsValidNode
{
get
{
if (enabled == null)
if (isValidNode == null)
{
enabled = IsEnabled();
return (bool) enabled;
isValidNode = !IsNodeNull(Node.CachedValue);
}

return (bool) enabled;
return (bool) isValidNode;
}

}
Expand Down Expand Up @@ -176,13 +179,14 @@ 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.

var gizmos = GetGizmos(false);
if (!Enabled || null == gizmos || !gizmos.Any()) return;
if (!IsEnabled() || null == gizmos || !gizmos.Any()) return;

var ray = BackgroundPreviewViewModel.GetClickRay(mouseButtonEventArgs);
if (ray == null) return;
Expand Down Expand Up @@ -232,7 +236,7 @@ protected virtual void MouseUp(object sender, MouseButtonEventArgs e)
/// <param name="mouseEventArgs"></param>
protected virtual void MouseMove(object sender, MouseEventArgs mouseEventArgs)
{
if (!Enabled) return;
if (!IsEnabled()) return;

var clickRay = BackgroundPreviewViewModel.GetClickRay(mouseEventArgs);
if (clickRay == null) return;
Expand Down Expand Up @@ -452,13 +456,13 @@ 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();

active = UpdatePosition();

if (!Enabled)
if (!IsEnabled())
{
return packages;
}
Expand Down Expand Up @@ -577,23 +581,23 @@ public RenderPackageCache BuildRenderPackage()

/// <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>
// TODO: Make private in 3.0.
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: Make private in 3.0
// 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 IsNodeNull(Node.CachedValue);
Expand Down