Skip to content

Commit

Permalink
DYN-2273 - Fix crash by compiling null input to null AST node (#10127)
Browse files Browse the repository at this point in the history
* fix crash by compiling null input to null node

* add test

* update recorded test to reflect null value of downstream node

* remove unused usings
  • Loading branch information
aparajit-pratap authored Nov 13, 2019
1 parent 9d06b82 commit 89465ff
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/DynamoCore/Engine/CodeGeneration/AstBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ private void CompileToAstNodes(
NodeModel inputModel = inputTuple.Item2;
AssociativeNode inputNode = inputModel.GetAstIdentifierForOutputIndex(outputIndexOfInput);

// If there are any null AST's (for e.g. if there's an error in the input node),
// graph update for the given node is skipped.
Validity.Assert(inputNode != null, "Shouldn't have null nodes in the AST list");

inputAstNodes.Add(inputNode);
inputAstNodes.Add(inputNode ?? new NullNode());
}
else
{
Expand Down Expand Up @@ -237,7 +233,7 @@ private void CompileToAstNodes(
}

#if DEBUG
Validity.Assert(inputAstNodes.All(n => n != null),
Validity.Assert(inputAstNodes.All(n => n != null),
"Shouldn't have null nodes in the AST list");
#endif

Expand Down
33 changes: 33 additions & 0 deletions test/DynamoCoreTests/CustomNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,39 @@ public void TestCustomNodeInSyncWithDefinition()
Assert.AreEqual("bool", customInstance.InPorts.First().ToolTip);
}

[Test]
public void UpdateCBNInCustomNodeDef_DoesNotCrash()
{
var basePath = Path.Combine(TestDirectory, @"core\CustomNodes\");

OpenModel(Path.Combine(basePath, "cbn_customnode_crash.dyn"));

// Assert custom node instance executes successfully
AssertPreviewValue("12d33f2a354a4e65ac06a3c783a7e679", "this is a custom node");

var customWorkspace = CurrentDynamoModel.CustomNodeManager.LoadedWorkspaces.FirstOrDefault(x => x != null);

// Navigate to custom node workspace
CurrentDynamoModel.AddWorkspace(customWorkspace);

// Extract cbn from custom node WS
var cbn = customWorkspace.Nodes.FirstOrDefault(x => x is CodeBlockNodeModel) as CodeBlockNodeModel;

// Edit CBN in custom node definition to introduce syntax error,
// update custom node definition and re-execute
Assert.DoesNotThrow(() =>
{
CurrentDynamoModel.ExecuteCommand(
new DynamoModel.UpdateModelValueCommand(
customWorkspace.Guid,
cbn.GUID,
"Code",
"1...10"));
});

AssertPreviewValue("12d33f2a-354a-4e65-ac06-a3c783a7e679", null);
}

[Test]
public void TestGroupsOnCustomNodes()
{
Expand Down
2 changes: 2 additions & 0 deletions test/DynamoCoreWpfTests/RecordedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5614,6 +5614,8 @@ public void TestConnectedCBNInErrorStateDoesNotCrash()
Assert.IsNotNull(node);
Assert.IsTrue(node.IsInErrorState);
Assert.AreEqual(1, node.AllConnectors.Count());

AssertPreviewValue("44115db6-bf0b-478a-90f6-2719eb65b70d", null);
}
});
}
Expand Down
113 changes: 113 additions & 0 deletions test/core/CustomNodes/cbn_customnode_crash.dyf
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"Uuid": "02464870-e36f-4b00-b9c5-390b72339821",
"IsCustomNode": true,
"Category": "Test",
"Description": "",
"Name": "cbn_customnode_crash",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "\"this is a custom node\";",
"Id": "7cd8efe791994faa9f54ab308421df12",
"Inputs": [],
"Outputs": [
{
"Id": "85973fe62ed0483da3c8181c85299050",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CustomNodes.Output, DynamoCore",
"NodeType": "OutputNode",
"ElementResolver": null,
"Symbol": "",
"Id": "54eec7da789b4e8db824e0a829c62c85",
"Inputs": [
{
"Id": "e7a8c6bc05aa413297514da41776ae34",
"Name": "",
"Description": "",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [],
"Replication": "Disabled",
"Description": "A function output, use with custom nodes"
}
],
"Connectors": [
{
"Start": "85973fe62ed0483da3c8181c85299050",
"End": "e7a8c6bc05aa413297514da41776ae34",
"Id": "cd9ca725bd2b405fb92b78a02a655dd3"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [],
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": false,
"IsVisibleInDynamoLibrary": true,
"Version": "2.5.0.6797",
"RunType": "Manual",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"NodeViews": [
{
"ShowGeometry": true,
"Name": "Code Block",
"Id": "7cd8efe791994faa9f54ab308421df12",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 250.0,
"Y": 0.0
},
{
"ShowGeometry": true,
"Name": "Output",
"Id": "54eec7da789b4e8db824e0a829c62c85",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 553.0,
"Y": 0.0
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}
78 changes: 78 additions & 0 deletions test/core/CustomNodes/cbn_customnode_crash.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"Uuid": "55c196e1-8972-4a4d-907e-608fd66455a8",
"IsCustomNode": false,
"Description": null,
"Name": "cbn_customnode_crash",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.CustomNodes.Function, DynamoCore",
"FunctionSignature": "02464870-e36f-4b00-b9c5-390b72339821",
"FunctionType": "Graph",
"NodeType": "FunctionNode",
"Id": "12d33f2a354a4e65ac06a3c783a7e679",
"Inputs": [],
"Outputs": [
{
"Id": "d3f9c2bcdeff4edca78420fe1397bc7e",
"Name": "",
"Description": "return value",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": ""
}
],
"Connectors": [],
"Dependencies": [
"02464870-e36f-4b00-b9c5-390b72339821"
],
"NodeLibraryDependencies": [],
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.5.0.6797",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"NodeViews": [
{
"ShowGeometry": true,
"Name": "cbn_customnode_crash",
"Id": "12d33f2a354a4e65ac06a3c783a7e679",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 326.0,
"Y": 252.0
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}

0 comments on commit 89465ff

Please sign in to comment.