godotengine / godotengine/godot

Setting shader parameter to const array causes error when material is freed

Open
#97,343 2 comments 2 reactions 0 assignees View on GitHub
bug confirmed topic:gdscript topic:shaders
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in: v4.3.stable.steam [77dcf97d8], v4.4.dev2.official [97ef3c837], v4.0.stable.official [92bee43ad]
- Not reproducible in: v2.1.stable.official, v3.0.stable.official, v3.5.1.stable.official [6fed1ffa3]

### System information

Godot v4.3.stable (77dcf97d8) - Windows 10.0.22631 - Vulkan (Mobile) - integrated Intel(R) Iris(R) Xe Graphics (Intel Corporation; 31.0.101.5186) - 13th Gen Intel(R) Core(TM) i7-1360P (16 Threads)

### Issue description

If a shader parameter on a material is set to an array that is declared as const, the engine erroneously attempts to clear the array when the material is freed. This results in an error in the debugger tab, "clear: Array is in read-only state". In the MRP, I achieved this with the following code:

```gdscript
const TEST_CONST = []

func _ready() -> void:
var new_node = Node2D.new()
new_node.material = ShaderMaterial.new()
new_node.material.set_shader_parameter("test", TEST_CONST)
new_node.queue_free()
```

### Steps to reproduce

Run the minimal reproduction project and check the debugger tab.

### Minimal reproduction project (MRP)

[clearbug.zip](https://github.com/user-attachments/files/17091629/clearbug.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the clearbug.zip minimal reproduction and the _ready() sequence that assigns TEST_CONST through ShaderMaterial.set_shader_parameter() before calling queue_free(). Reproduce the debugger error, then trace the material-freeing path to identify why the const array is cleared. Done means freeing the material no longer reports "Array is in read-only state".

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.