nolanderc / glsl_analyzer

Language server for GLSL (autocomplete, goto-definition, formatter, and more)
GNU General Public License v3.0
171 stars 4 forks source link

Crash on hover #2

Closed vdrn closed 10 months ago

vdrn commented 10 months ago

Trying to hover anything will result in crash:

debug: hover word: 'normals_uv'
thread 62471 panic: reached unreachable code
/home/runner/work/glsl_analyzer/glsl_analyzer/src/Document.zig:0:0: 0x237662 in parseTree (glsl_analyzer)
/home/runner/work/glsl_analyzer/glsl_analyzer/src/analysis.zig:298:50: 0x23911e in visibleSymbols (glsl_analyzer)
/home/runner/work/glsl_analyzer/glsl_analyzer/src/main.zig:540:57: 0x23c846 in completionsAtPosition (glsl_analyzer)
/home/runner/work/glsl_analyzer/glsl_analyzer/src/main.zig:605:34: 0x23ee55 in textDocument/hover (glsl_analyzer)
/home/runner/work/glsl_analyzer/glsl_analyzer/src/main.zig:276:45: 0x24b65a in dispatchRequest (glsl_analyzer)
/home/runner/work/glsl_analyzer/glsl_analyzer/src/main.zig:250:59: 0x251b98 in main (glsl_analyzer)
/opt/hostedtoolcache/zig/0.12.0-dev.790/x64/lib/std/start.zig:486:37: 0x25414a in main (glsl_analyzer)
/opt/hostedtoolcache/zig/0.12.0-dev.790/x64/lib/libc/musl/src/env/__libc_start_main.c:95:7: 0x2b0d72 in libc_start_main_stage2 (/opt/hostedtoolcache/zig/0.12.0-dev.790/x64/lib/libc/musl/src/env/__libc_start_main.c)
Unwind error at address `exe:0x2b0d72` (error.AddressOutOfRange), trace may be incomplete

Crash does not happen and hover works fine if there are no #include directives in file. Using latest release x86_64-linux-musl on Ubuntu 20.04. Please let me know if you need more info.

nolanderc commented 10 months ago

Hi! Thanks for reporting this, seems I never tested with more than 1 #include.

This should be fixed in the latest release (v1.0.5).

vdrn commented 10 months ago

Hey thanks for quick response. I'm still getting the same error. I'm using a different #version of glsl so it could be connected to that.. This triggers the error:

#version 130
#include "shader_flags.glsl"

varying vec2 uv;
uniform sampler2D Texture;

void main() {
  lowp vec4 tex = texture2D(Texture, uv);
  gl_FragData[0] = tex;
}

shader_flags.glsl can contain anything (a bunch of #defines or even be empty) and the crash will still happen.

nolanderc commented 10 months ago

Ah yes, I was able to reproduce your issue: if there's an empty file, the syntax tree will be empty (except for the root node). I removed a stray assert in 272fe483f03deae395577d230eb0415c333b97d4 and now it works for me.

Try v1.0.6 and see if it works for you as well!

vdrn commented 10 months ago

Ok, now it works fine if included file is empty or it contains functions/structs. But, if included file contains #defines, it stops working. It does not crash or report error, just returns empty responses for all requests. So, for example, the same above example with shader_flags.glsl containing:

#define ENABLE_BLOOM 1
nolanderc commented 10 months ago

Ah, clearly I had that assert in there for a reason. There was a loop which only terminates under the assumption that every syntax node has at least one child.

Thank you for being so patient. Hopefully v1.0.7 does the trick! :crossed_fingers:

vdrn commented 10 months ago

No problem, I'm glad to be of help. It's working perfectly now!

nolanderc commented 10 months ago

Alright! Thank you for your time! :)