Godot version:
3.2.2 beta 3
OS/device including version:
Geforce GTX 1650
GLES3
Issue description:
This issue is for godot shader language, not GDscript.
In a for loop, i want to look up a value in an array, clamping the index between zero and array length minus 1. This is a very common use case, and others will probably encounter this aswell.
This crashes the shader, without error message:
int index = clamp(i + levels, 0, array.length() - 1);
This works fine, when storing the array length in an integer first:
int length = array.length();
int index = clamp(i + levels, 0, length - 1);
Minimal reproduction project:
shader array length.zip
In the new_shader.shader file, comment the bugged version and uncomment the working version to toggle between them. The shader is not very good at all, but it shows the bug just fine.
@fossegutten Please upload a minimal reproduction project to make this easier to troubleshoot.
Done
For some reason this line :int targetIndex = clamp(i + levels_shifted, 0, array.length() - 1); transforms to int m_targetIndex=clamp((m_i+material.m_levels_shifted), 0, m_array.(length()-1)); I will investigate this
Most helpful comment
For some reason this line :
int targetIndex = clamp(i + levels_shifted, 0, array.length() - 1);transforms toint m_targetIndex=clamp((m_i+material.m_levels_shifted), 0,m_array.(length()-1)); I will investigate this