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 Regression with GetCLRObject impacting Node Preview and Tessellation #13363

Merged
merged 2 commits into from
Sep 30, 2022
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe GetClassNodeAtIndex was also introduced as part of the previous fixes. I suppose it's no longer needed as this line of code has been removed. Can the function, therefore, be removed?

Copy link
Contributor Author

@saintentropy saintentropy Sep 30, 2022

Choose a reason for hiding this comment

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

Yep it can be... I will file a follow up to re-look at this optimization. And we can either to fix the optimization or clear up that function too

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