### Godot version

Godot Engine v4.0.beta9.mono.official.e780dc332

### System information

Vulkan API 1.3.205 - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce RTX 3070 Ti Laptop GPU

### Issue description

When using a sampler2d[] in a shader, the game window will not close and the task must be killed/forced closed.  Debugging shows that the code is frozen on this method: godotsharp_internal_refcounted_disposed;




### Steps to reproduce

In the attached project, there is a shader "foliageShader.gdshader" that contains a sampler2d[].  If you run the project as is and then just click X to close the window, you should see the described behavior.  Changing the shader to a single sampler2d should cause the issue to go away.

### Minimal reproduction project

[Repro (2).zip](https://github.com/godotengine/godot/files/10298745/Repro.2.zip)

memdelete_arr(global_shader_uniforms.buffer_values);
	memdelete_arr(global_shader_uniforms.buffer_usage);
	memdelete_arr(global_shader_uniforms.buffer_dirty_regions);
	glDeleteBuffers(1, &global_shader_uniforms.buffer);
	singleton = nullptr;
}
int32_t MaterialStorage::_global_shader_uniform_allocate(uint32_t p_elements) {
	int32_t idx = 0;
	while (idx + p_elements <= global_shader_uniforms.buffer_size) {
		if (global_shader_uniforms.buffer_usage[idx].elements == 0) {
			bool valid = true;
			for (uint32_t i = 1; i < p_elements; i++) {
				if (global_shader_uniforms.buffer_usage[idx + i].elements > 0) {
					valid = false;
					idx += i + global_shader_uniforms.buffer_usage[idx + i].elements;
					break;
				}
			}
			if (!valid) {
				continue; 
			}
			return idx;
		} else {
			idx += global_shader_uniforms.buffer_usage[idx].elements;
		}
	}
	return -1;
}
void MaterialStorage::_global_shader_uniform_store_in_buffer(int32_t p_index, RS::GlobalShaderParameterType p_type, const Variant &p_value) {