Godot: Shader language: Shader crashes when subtracting from array length

Created on 3 Jun 2020  路  3Comments  路  Source: godotengine/godot

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.

bug shaders

Most helpful comment

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

All 3 comments

@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

Was this page helpful?
0 / 5 - 0 ratings