Repository: godot
Issue: Godot crashes along with Nvidia driver making system unstable on Nivdia Optimus Linux system
Labels: bug,platform:linuxbsd,topic:rendering,needs testing,crash

### Godot version

v4.1.1.stable.flathub [bd6af8e0e]

### System information

Godot v4.1.1.stable (bd6af8e0e) - Freedesktop SDK 23.08 (Flatpak runtime) - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1660 Ti (nvidia) - Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 Threads)

### Issue description

Apparently currently running Godot 4.1.1 (Flatpak, host is Fedora Silverblue 39 Beta) on my system always ends up with eventually Godot stopping responding and the Nvidia card (driver is 535.104.05) crashing until I reboot.

I do not know if it's a bug in the Nvidia driver or in Godot, so I'm filling an issue here.

```
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: handle_crash: Program crashed with signal 11
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: Engine version: Godot Engine v4.1.1.stable.flathub (bd6af8e0ea69167dd0627f3bd54f9105bda0f8b5)
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: Dumping the backtrace. Please include this when reporting the bug to the project developer.
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: ERROR: FATAL: Index p_index = 1 is out of bounds (size() = 0).
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]:    at: get (./core/templates/cowdata.h:155)
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: ================================================================
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: handle_crash: Program crashed with signal 4
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: Engine version: Godot Engine v4.1.1.stable.flathub (bd6af8e0ea69167dd0627f3bd54f9105bda0f8b5)
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: Dumping the backtrace. Please include this when reporting the bug to the project developer.
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]: ERROR: FATAL: Index p_index = 1 is out of bounds (size() = 0).
set 22 20:43:57 centauro org.godotengine.Godot.desktop[16003]:    at: get (./core/templates/cowdata.h:155)
```

This Godot crash apparently can bork both the iGPU and the dGPU:

```
set 22 20:43:46 centauro kernel: NVRM: GPU at PCI:0000:01:00: GPU-60a9bb49-90ee-5995-7b62-7b249c46239d
set 22 20:43:46 centauro kernel: NVRM: Xid (PCI:0000:01:00): 79, pid='<unknown>', name=<unknown>, GPU has fallen off the bus.
set 22 20:43:46 centauro kernel: NVRM: GPU 0000:01:00.0: GPU has fallen off the bus.
```

```
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57d:0:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:0:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:1:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:2:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:3:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:4:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:5:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:6:0:0x0000000f
set 22 20:43:57 centauro kernel: nvidia-modeset: ERROR: GPU:0: Failed to query display engine channel state: 0x0000c57e:7:0:0x0000000f
```

```
set 22 20:44:05 centauro kernel: nvidia-modeset: ERROR: GPU:0: Error while waiting for GPU progress: 0x0000c57d:0 2:0:4048:4040
```

```
set 22 20:44:13 centauro kernel: i915 0000:00:02.0: [drm] *ERROR* Atomic update failure on pipe A (start=53185 end=53186) time 232 us, min 1073, max 1079, scanline start 1066, end 1081
set 22 20:44:15 centauro kernel: nvidia-modeset: ERROR: GPU:0: Error while waiting for GPU progress: 0x0000c57d:0 2:0:4048:4040
```

### Steps to reproduce

Basically, opening my current project (It's a Godot 3.5 project I converted to Godot 4.x) and trying to do stuff for a while (for example, I  have been working on improving the graphics on that project).

After a while Godot freezes and, when it is killed, the Nvidia card is borked.

### Minimal reproduction project

N/A