Skip to content

Commit

Permalink
Fix Regression with GetCLRObject impacting Node Preview and Tessellat…
Browse files Browse the repository at this point in the history
…ion (#13363)

* RevertCode

* Remove clear function

Co-authored-by: Craig Long <craig.long@autodesk.com>
  • Loading branch information
saintentropy and saintentropy authored Sep 30, 2022
1 parent 912a25b commit f50c788
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
35 changes: 8 additions & 27 deletions src/Engine/ProtoCore/Reflection/GraphicDataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
Expand Down Expand Up @@ -141,50 +141,31 @@ internal List<IGraphicItem> GetGraphicItems(DSASM.StackValue svData, RuntimeCore
return null;
}

//Store marshaller for repeated calls to GetCLRObject. Used for short-circuit of re-allocation of marshaller / interpreter object.
private static Interpreter interpreter;
private static ProtoFFI.FFIObjectMarshaler marshaler;

internal object GetCLRObject(StackValue svData, RuntimeCore runtimeCore)
{
if (null == runtimeCore.DSExecutable.classTable)
return null;

//The GetCLRObject function is typically utilized to retrieve a ClrObject from a StackValue of type pointer.
//There is an edge cases for pointers where the pointer references a non CLR object. This code
//checks for this edge case by verifying that the requested StackValue pointer is associated with an
//imported library. An example is the "Function" pointer which does not have an associated CLRObject.
//In that case, the return value should be null.
var classNode = runtimeCore.DSExecutable.classTable.GetClassNodeAtIndex(svData.metaData.type);
if (classNode != null && !classNode.IsImportedClass)
{
IList<ClassNode> classNodes = runtimeCore.DSExecutable.classTable.ClassNodes;
if (null == classNodes || (classNodes.Count <= 0))
return null;
}

if (marshaler != null)
{
return marshaler.UnMarshal(svData, null, interpreter, typeof(object));
}
ClassNode classnode = runtimeCore.DSExecutable.classTable.ClassNodes[svData.metaData.type];
if (!classnode.IsImportedClass) //TODO: look at properties to see if it contains any FFI objects.
return null;

try
{
interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore, false);
ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore, false);
var helper = ProtoFFI.DLLFFIHandler.GetModuleHelper(ProtoFFI.FFILanguage.CSharp);
marshaler = helper.GetMarshaler(runtimeCore);
var marshaler = helper.GetMarshaler(runtimeCore);
return marshaler.UnMarshal(svData, null, interpreter, typeof(object));
}
catch (System.Exception)
{
marshaler = null;
return null;
}
}

internal static void ClearMarshaller()
{
interpreter = null;
marshaler = null;
}
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Engine/ProtoCore/RuntimeCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using ProtoCore.DSASM;
using ProtoCore.Lang;
using ProtoCore.Lang.Replication;
using ProtoCore.Mirror;
using ProtoCore.Runtime;
using ProtoCore.Utils;
using ProtoFFI;
Expand Down Expand Up @@ -272,7 +271,6 @@ public void Cleanup()
{
OnDispose();
CLRModuleType.ClearTypes();
GraphicDataProvider.ClearMarshaller();
}

public void NotifyExecutionEvent(ExecutionStateEventArgs.State state)
Expand Down

0 comments on commit f50c788

Please sign in to comment.