Custom GLSL shaders fail to compile with "#version must appear on the first line" error
When attempting to use a custom GLSL shader module with Glava, the compilation consistently fails with the error: preprocessor error: #version must appear on the first line. This occurs even when the #version directive is confirmed to be the absolute first line of the shader file, without any preceding characters or whitespace.
This issue does not affect built-in modules (e.g., bars), which compile and run correctly. This suggests the problem lies within Glava's handling of custom shader loading/compilation, rather than the shader file itself or the system's GLSL compiler.
Steps to Reproduce:
- Ensure Glava is installed and working with default modules (e.g., glava runs bars successfully).
- Create a new directory for a custom Glava module, e.g., /home/meteor-storm/.config/glava/my_custom_module/.
- Inside this directory, create a file named 1.frag with the following minimal GLSL content (ensuring #version is the very first character):
1 #version 330 core
2 out vec4 fragColor;
3 void main() {
4 fragColor = vec4(1.0, 0.0, 0.0, 1.0); // Red color
5 }
- Modify ~/.config/glava/rc.glsl to use this new module: Change #request mod bars to #request mod my_custom_module.
- Run Glava from the terminal: glava
Expected Behavior: Glava should successfully compile and render the custom shader (e.g., a solid red background).
Actual Behavior: Glava crashes with the following error message:
1 Shader compilation failed for '/home/meteor-storm/.config/glava/my_custom_module/1.frag':
2 0:11(1): preprocessor error: #version must appear on the first line
3 Аварийный останов
Environment: * Operating System: Void Linux * Desktop Environment: XFCE * Glava Version: glava --version output: GLava (glava) unknown (stable, unix/fhs) * GPU/Drivers: Mesa Intel(R) Iris(R) Xe Graphics (ADL GT2), 4.6 (Compatibility Profile) Mesa 25.1.3 535.113.01)
Relevant Logs/Output:
Output of glava --verbose:
1 Using backend: 'glx'
2 Loading module: 'my_custom_module'
3 found GLSL stage: '1.frag'
4 compiling: '1.frag'
5 Shader compilation failed for '/home/meteor-storm/.config/glava/my_custom_module/1.frag':
6 0:11(1): preprocessor error: #version must appear on the first line
7 Аварийный останов
Output of hexdump -C /home/meteor-storm/.config/glava/my_custom_module/1.frag | head -n 2 (confirming #version is on the first line):
1 00000000 23 76 65 72 73 69 6f 6e 20 33 33 30 20 63 6f 72 |#version 330 cor|
2 00000010 65 0a 6f 75 74 20 76 65 63 34 20 66 72 61 67 43 |e.out vec4 fragC|
Analysis/Possible Cause (from external research): Based on similar issues found for glslViewer (which exhibits the same error), it's possible that Glava automatically adds a "prolog" (some text/code) to the beginning of the shader program before compilation. If this prolog is inserted before the #version directive, it would cause the GLSL compiler to throw this error, as #version must be the absolute first line. A potential fix would involve checking if the first line of the user-provided shader is #version, and if so, moving that line to the beginning of Glava's internal prolog before passing the combined source to the GLSL compiler.