Repository: godot
Issue: Custom Theme Resource Written in C# Crashes Editor
Labels: bug,topic:editor,topic:dotnet,crash

### Godot version

3.3.2.stable.mono.official

### System information

Windows 10 20H2 19042.1052, Intel i7-10750H CPU, RTX 2070 Max-Q GPU

### Issue description

#### The Project:
I've been working on a custom Theme resource (that I named AutoTheme) that automatically sets all theme styles based on several input parameters, very similar to how the theme editor in Godot's editor settings works. I decided to write the resource script in C# and it uses the Tool keyword so it can update in the editor. I also created an editor plugin that registers the AutoTheme as a resource type.

What AutoTheme does, in a nutshell, is takes the user input parameters and uses them to generate a list of theme colors and theme styles. It also selects either a light or dark set of icons to use. Once the colors and styles are generated, it goes through the theme properties for every control type and assigns each a style, color, or icon. I setup AutoTheme to refresh every time a user input parameter changes, as long as the "Auto Refresh" option is checked.

#### The Bug:
I ran into a problem where, when I am using an AutoTheme resource, that after I re-build the solution the editor will consistently crash either after a little time or when I change settings on the AutoTheme resource. The crash only happens after a re-build and if the AutoTheme resource is loaded in the resource editor. 

When the crash happens, Godot reports this singular error to the command line:
```
ERROR: free_instance_binding_data: FATAL: Condition "!GDMonoUtils::is_thread_attached()" is true.
   At: modules/mono/csharp_script.cpp:1344
```

I tried narrowing the cause down to one triggering event, but I was unable to isolate a specific call that would trigger the crash. The closest I got was determining that the crash only happens if my code that sets the parameters on the base Theme resource gets called (found within AutoTheme.ApplyChanges(), line 654 of AutoTheme.cs). I failed to reproduce the crash with simpler test scripts that mimic parts of what my AutoTheme script does. 

I've attached a minimal reproduction project that contains more details in the ReadMe.txt file as well as a demo scene and my AutoTheme class that is causing the crash.

I've tested this problem on Godot 3.3 and 3.3.2 and it occurs on both.

### Steps to reproduce

To reproduce this bug, in the attached reproduction project do the following:
1) Open Custom_Theme found at res://resources/themes/Custom_Theme.tres (or attached to node Main in the Main scene).
2) Make some arbitrary adjustments to Custom_Theme (I normally change Base Color and Icon and Font Color). Also make sure "Auto Refresh" is checked.
3) Press build or run the app.
4) Return to Custom_Theme and start messing with the settings. After changing settings enough, it should eventually crash. Sometimes the crash happens very quickly, other times it takes up to a minute.

### Minimal reproduction project

[Custom C# Theme Crash.zip](https://github.com/godotengine/godot/files/6673039/Custom.C.Theme.Crash.zip)