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

An option to enable a headless ActiveDoc #703

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from

Conversation

spigach-tt
Copy link

Context

Many Grasshopper plugins rely on RhinoDoc.ActiveDoc for things like tolerances and units. By default, a Compute instance does not instantiate an ActiveDoc, which results in a NullReferenceException when plugins attempt to access its properties. There are workarounds that rely on the Grasshopper.Utility class, but those have to be implemented by the plugin's developer, which means that a number of third-party plugins cannot run on Compute.

Purpose

The purpose of this pull request is to give users the option to create a headless RhinoDoc.ActiveDoc when they launch an instance of Compute. This will allow Grasshopper plugins to access RhinoDoc.ActiveDoc properties without throwing an exception.

Description

The users will now be able to set a local environment variable called RHINO_COMPUTE_CREATE_HEADLESS_DOC. The value of this variable can be set to either true or false with false being the default. This variable is checked by the Load() method of the compute.geometry.Config static class and its value is assigned to the CreateHeadlessDoc property.

Each time the GrasshopperSolveHelper method of the ResthopperEndpointsModule is invoked, it checks whether Config.CreateHeadlessDoc is set to true. If it is, a brand new headless document is instantiated with tolerances and units determined by the input object. To clarify, a brand new ActiveDoc is created at a worker level for each Compute request.

Testing

This branch has been tested with both Hops and direct REST API calls from Python. The target Grasshopper script contained a C# component with calls to the ActiveDoc properties. Testing from Python was designed to flood several Compute workers with concurrent requests, each containing a unique combination of tolerances and units. Consistency between input ActiveDoc settings and the settings reported by the Grasshopper script was checked for each invocation to rule out possible conflicts between parallel ActiveDoc instances. No discrepancies or inconsistencies have been identified while testing under significant load.

image

@andyopayne
Copy link
Contributor

Hey Sergey. Thanks for putting together this PR. See my comments below:

  1. Your code never disposes the headless documents. Creating a doc and not disposing it will cause memory issues. Thus, I think you need to add the following lines just prior to the returnJson being sent back as the response (around line 117 in ResthopperEndpoints.cs).
if (RhinoDoc.ActiveDoc is object)
    RhinoDoc.ActiveDoc.Dispose();
  1. I think it would be a good idea to inform the user (in the console) that headless documents will be created/used. I think you may want to add something like this to Program.cs around line 48.
if(Config.CreateHeadlessDoc)
    Log.Information("Compute to use headless Rhino documents");
  1. I pushed a few commits to the 8.x branch on Monday. Please merge those latest changes into your branch and make the PR include those changes.

Let me know if you have any follow up questions or concerns. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants