Rhino 8 Bug: GHPython GH_Component SDK Mode Broken

Hi McNeel,

Both GHPython components that ship with Rhino 8.4.24023.15001 break when running in SDK mode:

Best,

Anders

I just installed the latest 8.4 and can not replicate the issue.

  • Would you mind clearing the %appdata%\\McNeel\Rhinoceros\8.0\Plug-ins\IronPython (** cache and let RhinoPython install the libraries again.
  • Also it might be a conflict with the new IronPython. Try disabling RhinoCodePlugin plugin that loads the new editor and all new languages and test the legacy python again.

I just updated to 8.4 too and afraid it doesn’t resolve my issue:

I couldn’t find that exact folder, but tried deleting this one:

C:\Users\andersh\AppData\Roaming\McNeel\Rhinoceros\8.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)

Which was rebuilt on loading Rhino 8. but didn’t appear to fix the issue.

That does not appear to resolve it either. Here’s a quick video capture and my system info:

Rhino 8 System info

Rhino 8 SR4 2024-1-30 (Rhino 8, 8.4.24030.15001, Git hash:master @ 97577baf4e4ae40c7f2ed3ef4e802db24f2e82ae)
License type: Commercial, build 2024-01-30
License details: Cloud Zoo

Windows 11 (10.0.22631 SR0.0) or greater (Physical RAM: 32GB)
.NET 7.0.15

Computer platform: LAPTOP - Plugged in [100% battery remaining]

Hybrid graphics configuration.
Primary display: Intel(R) Iris(R) Xe Graphics (Intel) Memory: 1GB, Driver date: 11-7-2023 (M-D-Y).
> Integrated graphics device with 4 adapter port(s)
- Windows Main Display is laptop’s integrated screen or built-in port
Primary OpenGL: NVIDIA RTX 2000 Ada Generation Laptop GPU (NVidia) Memory: 8GB, Driver date: 6-26-2023 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 536.45
> Integrated accelerated graphics device (shares primary device ports)
- Video pass-through to primary display device

OpenGL Settings
Safe mode: Off
Use accelerated hardware modes: On
Redraw scene when viewports are exposed: On
Graphics level being used: OpenGL 4.6 (primary GPU’s maximum)

Anti-alias mode: 8x
Mip Map Filtering: Linear
Anisotropic Filtering Mode: High

Vendor Name: NVIDIA Corporation
Render version: 4.6
Shading Language: 4.60 NVIDIA
Driver Date: 6-26-2023
Driver Version: 31.0.15.3645
Maximum Texture size: 32768 x 32768
Z-Buffer depth: 24 bits
Maximum Viewport size: 32768 x 32768
Total Video Memory: 8188 MB

Rhino plugins that do not ship with Rhino

Rhino plugins that ship with Rhino
C:\Program Files\Rhino 8\Plug-ins\Commands.rhp “Commands” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\rdk.rhp “Renderer Development Kit”
C:\Program Files\Rhino 8\Plug-ins\RhinoRenderCycles.rhp “Rhino Render” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\rdk_etoui.rhp “RDK_EtoUI” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\NamedSnapshots.rhp “Snapshots”
C:\Program Files\Rhino 8\Plug-ins\MeshCommands.rhp “MeshCommands” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\IronPython\RhinoDLR_Python.rhp “IronPython” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\RhinoCycles.rhp “RhinoCycles” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\Grasshopper\GrasshopperPlugin.rhp “Grasshopper” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\Toolbars\Toolbars.rhp “Toolbars” 8.4.24030.15001
C:\Program Files\Rhino 8\Plug-ins\3dxrhino.rhp “3Dconnexion 3D Mouse”
C:\Program Files\Rhino 8\Plug-ins\Displacement.rhp “Displacement”
C:\Program Files\Rhino 8\Plug-ins\SectionTools.rhp “SectionTools”

I just had two of my colleagues check and they did not have the issue either, here’s a couple of screenshots with their Rhino 8 versions:


Edit: We noticed that I’m on a newer Rhino 7 than them, perhaps that might be related. Here’s my Rhino 7 system info:

Rhino 7 System Info

Rhino 7 SR37 2024-1-4 (Rhino 7, 7.37.24004.15001, Git hash:master @ e428f0ecb09d755f844c48e5098aba5f8baf55fa)
License type: Commercial, build 2024-01-04
License details: Cloud Zoo

Windows 11 (10.0.22631 SR0.0) or greater (Physical RAM: 32Gb)

Computer platform: LAPTOP - Plugged in [100% battery remaining]

Hybrid graphics configuration.
Primary display: Intel(R) Iris(R) Xe Graphics (Intel) Memory: 1GB, Driver date: 11-7-2023 (M-D-Y).
> Integrated graphics device with 4 adapter port(s)
- Windows Main Display is laptop’s integrated screen or built-in port
Primary OpenGL: NVIDIA RTX 2000 Ada Generation Laptop GPU (NVidia) Memory: 8GB, Driver date: 6-26-2023 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 536.45
> Integrated accelerated graphics device (shares primary device ports)
- Video pass-through to primary display device

OpenGL Settings
Safe mode: Off
Use accelerated hardware modes: On
Redraw scene when viewports are exposed: On
Graphics level being used: OpenGL 4.6 (primary GPU’s maximum)

Anti-alias mode: 8x
Mip Map Filtering: Linear
Anisotropic Filtering Mode: High

Vendor Name: NVIDIA Corporation
Render version: 4.6
Shading Language: 4.60 NVIDIA
Driver Date: 6-26-2023
Driver Version: 31.0.15.3645
Maximum Texture size: 32768 x 32768
Z-Buffer depth: 24 bits
Maximum Viewport size: 32768 x 32768
Total Video Memory: 8188 MB

Rhino plugins that do not ship with Rhino

Rhino plugins that ship with Rhino
C:\Program Files\Rhino 7\Plug-ins\Commands.rhp “Commands” 7.37.24004.15001
C:\Program Files\Rhino 7\Plug-ins\WebBrowser.rhp “WebBrowser”
C:\Program Files\Rhino 7\Plug-ins\rdk.rhp “Renderer Development Kit”
C:\Program Files\Rhino 7\Plug-ins\RhinoScript.rhp “RhinoScript”
C:\Program Files\Rhino 7\Plug-ins\IdleProcessor.rhp “IdleProcessor”
C:\Program Files\Rhino 7\Plug-ins\RhinoRenderCycles.rhp “Rhino Render” 7.37.24004.15001
C:\Program Files\Rhino 7\Plug-ins\rdk_etoui.rhp “RDK_EtoUI” 7.37.24004.15001
C:\Program Files\Rhino 7\Plug-ins\rdk_ui.rhp “Renderer Development Kit UI”
C:\Program Files\Rhino 7\Plug-ins\NamedSnapshots.rhp “Snapshots”
C:\Program Files\Rhino 7\Plug-ins\Alerter.rhp “Alerter”
C:\Program Files\Rhino 7\Plug-ins\IronPython\RhinoDLR_Python.rhp “IronPython” 7.37.24004.15001
C:\Program Files\Rhino 7\Plug-ins\RhinoCycles.rhp “RhinoCycles” 7.37.24004.15001
C:\Program Files\Rhino 7\Plug-ins\Grasshopper\GrasshopperPlugin.rhp “Grasshopper” 7.37.24004.15001
C:\Program Files\Rhino 7\Plug-ins\Toolbars\Toolbars.rhp “Toolbars” 7.37.24004.15001
C:\Program Files\Rhino 7\Plug-ins\3dxrhino.rhp “3Dconnexion 3D Mouse”
C:\Program Files\Rhino 7\Plug-ins\Displacement.rhp “Displacement”

Looks like it is the same bug as

I don’t think so, but might be wrong. That bug appears to be the Solution exception:Object reference not set to an instance of an object error message being raised when one of the two shipped GHPython components (the upper one if I recall) was first instantiated on the canvas. Which appears to be fixed in Rhino 8.4.24037.15001. The bug I’m reporting is when one instantiates either of the two GHPython components and sets its mode to GH_Component SDK Mode (or open an existing file using SDK Mode components) the error message:

Runtime error (ApplicationException): MyComponent must be of type ExecutingComponent, but is "IronPython.NewTypes.GhPython.Assemblies.ExecutingComponent_8$8"

Is raised, suggesting that from ghpythonlib.componentbase import executingcomponent as component might be borked for me somehow:

Perhaps it might be related to these changes to the new componentbase.pyfile (right):

I just updated to Rhino 8.5.24044.18001 and I’m afraid this issue persists. It means that Rhino 8 is a nonstarter for us/me (we’re currently evaluating when to roll it out for the entire office), as most of my internal modelling pipelines implement GHPython running in SDK mode :face_with_diagonal_mouth:

Hi Anders,

I’m gonna need your help to make my machine replicate this problem. Would you mind checking these for me:

  • Disable RhinoCodePlugin in plugin manager and load Rhino. See if the ironpython components behave now. I’m trying to see if there is a conflict between the ironpythons there

  • What paths are on your IronPython sys.path?

  • Run this code in the editor. I am trying to see if more than one GhPython assembly is loaded. That’s the assembly that contains the .ExecutingComponent type

from System import AppDomain

print("Name,Version,Location")
for loaded_assembly in AppDomain.CurrentDomain.GetAssemblies():
    try:
        loc = loaded_assembly.Location
    except:
        pass
    if 'GhPython' in loaded_assembly.GetName().Name:
	    print(
	        "{0},{1},{2}".format(
	            loaded_assembly.GetName().Name,
	            str(loaded_assembly.GetName().Version),
	            loc,
	        )
	    )
1 Like

Cheers @eirannejad, I’ll get back to you with these tests. But one thing I just thought to test was switching the .NET runtime from NETCore to NETFramework. This appears to be related (i.e. SDK mode seems to work when running NETFramework):


1 Like

Was hoping to update service release, but our IT department are unresponsive. But anywho, here’s my current system info and the requested information (@eirannejad):

System Info

Rhino 8 SR5 2024-2-13 (Rhino 8, 8.5.24044.18001, Git hash:master @ 3070dad8e8cced9e1b333ad92cd445f22730c23e)
License type: Commercial, build 2024-02-13
License details: Cloud Zoo

Windows 11 (10.0.22631 SR0.0) or greater (Physical RAM: 32GB)
.NET 7.0.16

Computer platform: LAPTOP - Plugged in [100% battery remaining]

Hybrid graphics configuration.
Primary display: Intel(R) Iris(R) Xe Graphics (Intel) Memory: 1GB, Driver date: 11-7-2023 (M-D-Y).
> Integrated graphics device with 4 adapter port(s)
- Windows Main Display is laptop’s integrated screen or built-in port
Primary OpenGL: NVIDIA RTX 2000 Ada Generation Laptop GPU (NVidia) Memory: 8GB, Driver date: 6-26-2023 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 536.45
> Integrated accelerated graphics device (shares primary device ports)
- Video pass-through to primary display device

OpenGL Settings
Safe mode: Off
Use accelerated hardware modes: On
Redraw scene when viewports are exposed: On
Graphics level being used: OpenGL 4.6 (primary GPU’s maximum)

Anti-alias mode: 8x
Mip Map Filtering: Linear
Anisotropic Filtering Mode: High

Vendor Name: NVIDIA Corporation
Render version: 4.6
Shading Language: 4.60 NVIDIA
Driver Date: 6-26-2023
Driver Version: 31.0.15.3645
Maximum Texture size: 32768 x 32768
Z-Buffer depth: 24 bits
Maximum Viewport size: 32768 x 32768
Total Video Memory: 8188 MB

Rhino plugins that do not ship with Rhino

Rhino plugins that ship with Rhino
C:\Program Files\Rhino 8\Plug-ins\Commands.rhp “Commands” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\rdk.rhp “Renderer Development Kit”
C:\Program Files\Rhino 8\Plug-ins\RhinoRenderCycles.rhp “Rhino Render” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\rdk_etoui.rhp “RDK_EtoUI” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\NamedSnapshots.rhp “Snapshots”
C:\Program Files\Rhino 8\Plug-ins\MeshCommands.rhp “MeshCommands” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\IronPython\RhinoDLR_Python.rhp “IronPython” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\RhinoCycles.rhp “RhinoCycles” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\Grasshopper\GrasshopperPlugin.rhp “Grasshopper” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\Toolbars\Toolbars.rhp “Toolbars” 8.5.24044.18001
C:\Program Files\Rhino 8\Plug-ins\3dxrhino.rhp “3Dconnexion 3D Mouse”
C:\Program Files\Rhino 8\Plug-ins\Displacement.rhp “Displacement”
C:\Program Files\Rhino 8\Plug-ins\SectionTools.rhp “SectionTools”

With NETCore runtime I’m getting the same behaviour as reported up here (i.e. broken SDK modes). With NETFramework runtime both GHPython components have functional SDK modes. I asked three of my colleagues to run the same test and they all had functional SDK modes on both runtimes. I can have them post their system info etc. if that might help.

For the two GHPython components, the paths seems to be consistent across runtimes and modes:

GHPython paths screenshots



If I enable RhinoCodePlugin, the paths also appear consistent across the two shipped IronPython script components and runtimes:

IronPython paths screenshots


Think we’re getting somewhere here. In NETFramework procedural mode I get one assembly loaded, but SDK mode has two loaded. While NETCore procedural mode has two loaded assemblies and SDK mode throws the type error initially reported above:


Thank you so much for the detailed tests. I think we found the problem. There are two GHPython.gha assemblies loaded and each have their own ExecutingComponent type definition. Somewhere in there IronPython component is compiling the MyComponent against one of the ExecutingComponent types but tries to assign it to the other and it fails.

The first GHPython.gha does not have a location which is odd. The only way I know that an assembly can be loaded this way is using Assembly.Load(byte[]) which I don’t believe we are using anywhere.

Do you have any *.ghpy files anywhere under %%APPDATA%\Grasshopper folder?

1 Like

Afraid not, there are no .ghpy files on my system. No .ghuser either (I had two custom GHPython components, but removed them as well during these tests).

Okay we need to see which code is loading the GHPython library from binary data. Let’s do one more test:

  • Open fresh Rhino (no grasshopper and preferable no other plugins)

  • Run ScriptEditor command to launch the new script editor

  • Open the script attached here:

  • Run the script once to activate the assembly load tracker

  • Keep editor open and launch Grasshopper, place IronPython components, etc.

  • DM me the log file on your desktop. It is named RhinoAssemblyTrace.log

RhinoAssemblyTracer.cs (928 Bytes)

The log file should have data looking like this:

1 Like

Cheers Ehsan, I’ll DM you the trace log and a video capture of the process.

1 Like

Ok confirmed GHPython is loaded twice and it does not happen on my machine for comparison. Here is the stack trace from the second load. I’m going to debug this stack and see what kind of code is being run when component is switched to SDK mode and why it would load a fresh copy of GHPython.rhp

The assembly is re-loaded on this line when component is being put into SDK mode:

GhPython.Forms.PythonScriptForm.switchTocomponentModeMenuItem_Click

------ GhPython, Version=8.5.24044.18001, Culture=neutral, PublicKeyToken=null
   at __RhinoCodeScript__.<>c__DisplayClass0_0.<__RunScript__>g__AssemblyLoaded|0(Object sender, AssemblyLoadEventArgs args)
   at System.Runtime.Loader.AssemblyLoadContext.<LoadFromPath>g____PInvoke|5_0(IntPtr ptrNativeAssemblyBinder, UInt16* ilPath, UInt16* niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
   at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
   at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
   at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
   at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
   at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
   at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
   at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
   at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at Microsoft.Scripting.Hosting.CompiledCode.Execute(ScriptScope scope)
   at RhinoPython.PyCompiledCode.Execute(PythonScript scope)
   at GhPython.Component.ScriptingAncestorComponent.SafeSolveInstance(IGH_DataAccess da)
   at GhPython.Component.SafeComponent.SolveInstance(IGH_DataAccess DA)
   at Grasshopper.Kernel.GH_Component.Solution_Compute_MixedAccess(GH_StructureIterator it)
   at Grasshopper.Kernel.GH_Component.ComputeData()
   at Grasshopper.Kernel.GH_Document.SolveAllObjects(GH_SolutionMode mode)
   at Grasshopper.Kernel.GH_Document.NewSolution(Boolean expireAllObjects, GH_SolutionMode mode)
   at Grasshopper.Kernel.GH_Document.NewSolution(Boolean expireAllObjects)
   at Grasshopper.Kernel.GH_Document.DocObjSolutionExpired(Object sender, GH_SolutionExpiredEventArgs e)
   at Grasshopper.Kernel.GH_DocumentObject.OnSolutionExpired(Boolean recompute)
   at Grasshopper.Kernel.GH_DocumentObject.ExpireSolution(Boolean recompute)
   at Grasshopper.Kernel.GH_ActiveObject.ExpireSolution(Boolean recompute)
   at GhPython.Forms.PythonScriptForm.SetDefinitionValue(Boolean close, Boolean expire)
   at GhPython.Forms.PythonScriptForm.switchTocomponentModeMenuItem_Click(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
1 Like

@AndersDeleuran

Find this file:

%APPDATA%\McNeel\Rhinoceros\8.0\Plug-ins\IronPython (<id>)\settings\lib\ghpythonlib\__init__.py where <id> is some guid string.

Replace the contents with this and reload Rhino:

# ghpythonlib package
__all__ = ["components", "treehelpers", "parallel", "componentbase", "component"]

import os.path as op
import clr
clr.AddReference("Grasshopper, Culture=neutral, PublicKeyToken=dda4f5ec2cd80803")

import System
import Grasshopper

try:
    clr.AddReference("GhPython")
except:
    ghdllpath = Grasshopper.Instances.ComponentServer.GetType().Assembly.Location
    System.Reflection.Assembly.LoadFrom(
        op.join(op.dirname(ghdllpath), "Components\GhPython.gha")
    )
    clr.AddReference("GhPython")

from ghpythonlib import components
from ghpythonlib import treehelpers
from ghpythonlib import parallel
from ghpythonlib import componentbase
from ghpythonlib import component

Ticket for reference:

RH-80581 ghpythonlib init code causes GhPython module to load twice

1 Like

Hoozaa, that indeed appears to solve it:

Do you know why my system has this issue, when my colleagues and yourself couldn’t reproduce it? Still wonder if it might have been something I did. But on the other hand, this is a brand new system where I’ve fiddled very little (so far)…

2 Likes

Sweet! Okay this doesn’t really change the behaviour of python component so I’m gonna merge this for Rhino 8.6

Thanks for helping me troubleshooting this.

1 Like