Repository: godot
Issue: Freeing a node on macOS + Godot Mono from `_GuiInput` causes a crash
Labels: bug,discussion,platform:macos,topic:editor,documentation,needs testing,crash,topic:3d

### Tested versions

- Reproducible in `v4.3.stable.mono.official [77dcf97d8]`
- Reproducible in `v4.4.dev.mono.custom_build.c602c168b`

### System information

Sonoma 14.6.1

### Issue description

Freeing a node right when Godot calls the `GridMapEditorPlugin` destructor causes a crash. This only seems to happen on macOS; I had several people test on Windows for a combined total of 50+ times and it didn't repro there. I also couldn't get this to repro from GDScript alone.

Stack trace for the crash:

```
================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.3.stable.mono.official (77dcf97d82cbfe4e4615475fa52ca03da645dbd8)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] invoke_previous_action(sigaction*, int, __siginfo*, void*, bool)
[2] 2   libsystem_platform.dylib            0x0000000194666584 _sigtramp + 56
[3] 3   libc++abi.dylib                     0x00000001945ed7b0 __dynamic_cast + 56
[4] Viewport::push_input(Ref<InputEvent> const&, bool) (in Godot) + 720
[5] Window::_window_input(Ref<InputEvent> const&) (in Godot) + 756
[6] GridMapEditorPlugin::~GridMapEditorPlugin()
[7] DisplayServerMacOS::_dispatch_input_event(Ref<InputEvent> const&)
[8] DisplayServerMacOS::_dispatch_input_event(Ref<InputEvent> const&) (in Godot) + 572
[9] Input::_parse_input_event_impl(Ref<InputEvent> const&, bool) (in Godot) + 2828
[10] Input::flush_buffered_events() (in Godot) + 136
[11] Input::release_pressed_events() (in Godot) + 20
[12] DisplayServerMacOS::release_pressed_events() (in Godot) + 40
[13] RendererCompositorRD::_create_current()
[14] 14  CoreFoundation                      0x000000019470a144 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
[15] 15  CoreFoundation                      0x000000019479e3d8 ___CFXRegistrationPost_block_invoke + 88
[16] 16  CoreFoundation                      0x000000019479e320 _CFXRegistrationPost + 440
[17] 17  CoreFoundation                      0x00000001946d8678 _CFXNotificationPost + 768
[18] 18  Foundation                          0x00000001957f52c4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
[19] 19  AppKit                              0x00000001980ce7f4 -[NSWindow resignKeyWindow] + 640
[20] 20  AppKit                              0x00000001980ce4dc _NXEndKeyAndMain + 128
[21] 21  AppKit                              0x00000001980cd5e4 -[NSApplication _handleDeactivateEvent:] + 724
[22] 22  AppKit                              0x0000000198768380 -[NSApplication(NSEventRouting) sendEvent:] + 1236
[23] Ref<DirAccess> DirAccess::_create_builtin<DirAccessMacOS>()
[24] DisplayServerMacOS::process_events() (in Godot) + 220
[25] OS_MacOS::run() (in Godot) + 156
[26] main (in Godot) + 392
[27] 27  dyld                                0x00000001942ab154 start + 2476
-- END OF BACKTRACE --
================================================================
The program '[47492] Godot' has exited with code 0 (0x0).
```

As a workaround, calling `QueueFree` instead of `Free` should fix the issue.

### Steps to reproduce

- Load the minimal repro from the attached `.zip`
- Hover your mouse rapidly around where the sprites show up. The chance of repro is quite high if you do this as soon as the program starts, so try to memorize where they'll show up and start hovering there.

[Quick video repro here](https://www.twitch.tv/adamlearnslive/clip/SecretivePlayfulSrirachaDatBoi-JR5MRHuRvN5batvh).

The most relevant code is this snippet, which simply frees one of the icons as soon as it receives mouse input:

```
public override void _GuiInput(InputEvent @event)
{
    AcceptEvent();
    Free();
}
```

### Minimal reproduction project (MRP)

[crashrepro.zip](https://github.com/user-attachments/files/18264164/crashrepro.zip)