Repository: godot
Issue: Editor crash when setting shader parameter for type uniform sampler2D array ("Attempting to initialize the wrong RID")
Labels: bug,topic:rendering,topic:editor,crash

### Godot version

v4.2.beta6.mono.official [64150060f]

### System information

Godot v4.2.beta5.mono - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2080 SUPER (NVIDIA; 31.0.15.3742) - Intel(R) Core(TM) i9-9900 CPU @ 3.10GHz (16 Threads)

Godot v4.2.beta6 - Linux Mint 21 (Vanessa) - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 (nvidia; 530.41.03) - Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz (24 Threads)

This was also successfully reproduced on macOS (ARM) and Linux Mint; i.e., this issue is not OS agnostic.

### Issue description

Sampler2D arrays are a new feature exclusive to Godot 4, but they appear to have not been tested _at all_.

While they work without issue when solely utilizing them in code, attempting to set a `uniform sampler2D[]` in the Godot property inspector will cause a crash on the next editor startup with the error "Attempting to initialize the wrong RID."

For relevant logs, please refer to the attached message in the reproduction project, courtesy of @johnnyninjutsu on Discord.

### Steps to reproduce

- Write a shader that utilizes a uniform sampler 2D array:
```glsl
shader_type canvas_item; //most likely will work with every shader type but was only tested with CanvasItem.

uniform sampler2D[23] bad_var;
```

- Assign the shader to a ShaderMaterial in a relevant node, and populate the sampler array. This has been provided in the repro project:

![image](https://github.com/godotengine/godot/assets/58347007/7a5da4f7-6622-4379-8815-e1f2db7d89f1)

- Save and restart Godot. If done correctly, the editor will immediately crash upon reopening, bricking the project until the shader cache and imports are removed.

The crash only occurs after restarting the editor, so ensure you entirely save the project with Ctrl/Cmd + S and restart Godot for a successful repro.

### Minimal reproduction project

[Sampler2dArrayRepro.zip](https://github.com/godotengine/godot/files/13373132/Sampler2dArrayRepro.zip)

Crash log:
```
ERROR: Attempting to initialize the wrong RID
   at: get_or_null (./core/templates/rid_owner.h:189)
ERROR: Parameter "mem" is null.
   at: initialize_rid (./core/templates/rid_owner.h:219)
ERROR: Parameter "shader" is null.
   at: shader_set_code (servers/rendering/renderer_rd/storage_rd/material_storage.cpp:1853)
ERROR: Parameter "shader" is null.
   at: shader_set_path_hint (servers/rendering/renderer_rd/storage_rd/material_storage.cpp:1930)
ERROR: Initializing already initialized RID
   at: get_or_null (./core/templates/rid_owner.h:182)
ERROR: Parameter "mem" is null.
   at: initialize_rid (./core/templates/rid_owner.h:214)
ERROR: Parameter "shader" is null.
   at: material_set_shader (servers/rendering/renderer_rd/storage_rd/material_storage.cpp:2108)
ERROR: Parameter "_fp" is null.
   at: _ref (core/variant/array.cpp:55)
ERROR: Parameter "_fp" is null.
   at: _ref (core/variant/array.cpp:55)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.2.beta6.official (64150060f89677eaf11229813ae6c5cf8a873802)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f002927e520] (??:0)
[2] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x326742a] (??:0)
[3] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x328f86d] (??:0)
[4] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x313c5a7] (??:0)
[5] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x46fa0b] (??:0)
[6] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x313e49c] (??:0)
[7] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x2901875] (??:0)
[8] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x4e5488] (??:0)
[9] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x39a8c14] (??:0)
[10] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x467f68] (??:0)
[11] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x3267450] (??:0)
[12] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x328f86d] (??:0)
[13] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x313c5a7] (??:0)
[14] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x46fa0b] (??:0)
[15] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x30cd8ac] (??:0)
[16] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x18bdf06] (??:0)
[17] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x1d70e69] (??:0)
[18] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x122f314] (??:0)
[19] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x122fd18] (??:0)
[20] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x3fd8cfd] (??:0)
[21] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x1240bc7] (??:0)
[22] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x3b8baa0] (??:0)
[23] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0xadb403] (??:0)
[24] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x11681dd] (??:0)
[25] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x3b264c8] (??:0)
[26] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x2087a44] (??:0)
[27] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x2088e4b] (??:0)
[28] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x208c5d1] (??:0)
[29] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x4f932d] (??:0)
[30] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x41ed16] (??:0)
[31] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f0029265d90] (??:0)
[32] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f0029265e40] (??:0)
[33] /home/john/builds/games/Godot_v4.2-beta6_linux.x86_64() [0x42a96a] (??:0)
-- END OF BACKTRACE --
================================================================
```

NOTE: The sample production project and crash log were provided by @johnnyninjutsu on the [Godot Engine Discord](https://discord.gg/4JBkykG), who collaborated with me in developing a working repro and writing up this issue. Talk can be found [here](https://discord.com/channels/212250894228652034/1082369329976315964/1082369329976315964).