Doc modification ScriptRunner vs InvokeOnUiThread

I have a method where I modify a headless document.
It works if I run it from a ScriptRunner command, but Rhino crashes if I try to to run it from a button, or via a button and InvokeOnUiThread.

public delegate void FiddleWithDocDelegate();

public static async void FiddleWithDoc() {
  1. Create a Headless Document
  2. Add some Breps
  3. Transform the Breps with `doc.Objects.Transform(brep, transform, replace=true);`

This is how I try to invoke it from a button:

button.Click += (object sender, EventArgs args) =>
  FiddleWithDocDelegate handler = FiddleWithDoc;
  RhinoApp.InvokeOnUiThread(handler, new object[0]);

Am I doing something obvious wrong here?


At which of the three steps is Rhino crashing?

Step 3. The stack traces points deep inside RhinoCommon, in the Transform method itself.

Ok, I’ll need to set up a test case to try and repeat this.

Do you have a simple example that shows this crash? I haven’t found the time to create a test case myself.

Sorry, no. I just moved the functionality into a cmd instead, and didn’t look back. It’s rock solid now.

Maybe I’ll try to create a minimal test case later.