### 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)

bv[1].z = v.basis.rows[2][1];
			bv[1].w = 0;
			bv[2].x = v.basis.rows[0][2];
			bv[2].y = v.basis.rows[1][2];
			bv[2].z = v.basis.rows[2][2];
			bv[2].w = 0;
			bv[3].x = v.origin.x;
			bv[3].y = v.origin.y;
			bv[3].z = v.origin.z;
			bv[3].w = 1;
		} break;
		default: {
			ERR_FAIL();
		}
	}
}
void MaterialStorage::_global_shader_uniform_mark_buffer_dirty(int32_t p_index, int32_t p_elements) {
	int32_t prev_chunk = -1;
	for (int32_t i = 0; i < p_elements; i++) {
		int32_t chunk = (p_index + i) / GlobalShaderUniforms::BUFFER_DIRTY_REGION_SIZE;
		if (chunk != prev_chunk) {
			if (!global_shader_uniforms.buffer_dirty_regions[chunk]) {
				global_shader_uniforms.buffer_dirty_regions[chunk] = true;
				global_shader_uniforms.buffer_dirty_region_count++;
			}
		}
		prev_chunk = chunk;
	}
}
void MaterialStorage::global_shader_parameter_add(const StringName &p_name, RS::GlobalShaderParameterType p_type, const Variant &p_value) {