[SOLVED]Weird behavior with lwjglx-debug-1.0.0.jar

Started by ilum, September 28, 2020, 19:23:06

Previous topic - Next topic

ilum

Hi,

    I was trying to see what kind of problems the debug jar catches so I ran a simple program that renders the basic triangle with the basic vertex and fragment shaders and to my surprise a render that works without the javaagent running, fails when using it it.
    These are the VM options I used:  -javaagent:<path>/lwjglx-debug-1.0.0.jar=d;t;o=trace.log
                                                      -XX:+UnlockExperimentalVMOptions
                                                      -XX:+UseZGC

I've attached the trace.log with the error but for a shorter read this is the part that baffles me
[trace][1] Shader source for shader [2]:
        1  #version 330 core
        2  layout (location=0) in vec3 aPos;
        3  
        4  void main() {
        5      gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
        6  }
[trace][1] (ShaderProgram.java:65)      glShaderSource(2, "#version 330 core\nlayout (location=0) in vec3 aPos;\n\nvoid main() {\n    gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n}\n")
[trace][1] (ShaderProgram.java:66)      glCompileShader(2)
[trace][1] (ShaderProgram.java:75)      glGetShaderi(2, GL_COMPILE_STATUS) = GL_TRUE
[trace][1] (ShaderProgram.java:68)      glAttachShader(1, 2)
[trace][1] (ShaderProgram.java:63)      glCreateShader(GL_FRAGMENT_SHADER) = 3
[trace][1] Shader source for shader [3]:
        1  #version 330 core
        2  out vec4 FragColor;
        3  
        4  void main() {
        5      FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
        6  }
[trace][1] (ShaderProgram.java:65)      glShaderSource(3, "#version 330 core\nout vec4 FragColor;\n\nvoid main() {\n    FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n}\n")
[trace][1] (ShaderProgram.java:66)      glCompileShader(3)
[trace][1] (ShaderProgram.java:75)      glGetShaderi(3, GL_COMPILE_STATUS) = GL_TRUE
[trace][1] (ShaderProgram.java:68)      glAttachShader(1, 3)
[trace][1] (ShaderProgram.java:33)      glLinkProgram(1)
[error][1] OpenGL debug message
  ID: 0x502
  Source: API
  Type: ERROR
  Severity: HIGH
  Message: GL_INVALID_OPERATION error generated. Object is not a program or shader object.
  Stacktrace: org.lwjgl.opengl.GL20C.nglGetShaderiv(Native Method)
              org.lwjgl.opengl.GL20C.glGetShaderi(GL20C.java:771)
              org.lwjgl.opengl.GL20.glGetShaderi(GL20.java:847)
              ShaderProgram.logShaderStatus(ShaderProgram.java:75)
              ShaderProgram.link(ShaderProgram.java:34)
              Main.loop(Main.java:116)
              Main.run(Main.java:37)
              Main.main(Main.java:24)
[trace][1] (Main.java:40)               glfwFreeCallbacks(window[1])
[info ] Destroying OpenGL context for window[1]
[trace] (Main.java:41)               glfwDestroyWindow(window[1])
[debug] Freeing GLFWErrorCallback
[trace] (Main.java:43)               glfwTerminate()
[trace] (Main.java:47)               glfwSetErrorCallback(null) =  pointer [0x23099BB0000]
[trace] (Main.java:48)               setCapabilities(null)


    Again, I don't understand why this works when I don't use the javaagent. I do have error reporting behavior in the shader class and I don't get any problem:
private void logShaderStatus(int shaderId, int statusToCheck) {
        try (MemoryStack stack = MemoryStack.stackPush()) {
            if (glGetShaderi(shaderId, statusToCheck) == NULL) {
                ByteBuffer infoLog = stack.malloc(256 * Integer.BYTES);
                glGetShaderInfoLog(shaderId, new int[256], infoLog);

                System.out.println(infoLog.asReadOnlyBuffer().toString());
            }
        }
    }

KaiHH

This error message:
QuoteGL_INVALID_OPERATION error generated. Object is not a program or shader object.
is generated by the OpenGL driver. When you see something like this, then you definitely generate invalid OpenGL calls.
There is also a difference between "the program works" as in "it renders what I expect" and: "the program does not generate any OpenGL errors".
I bet that at some point you call `glGetShaderi()` with a shader object id/handle that does not (any more?) represent a shader object. Maybe you deleted the shader object previously.
Do you have a minimal, complete and verifiable example program to check?

ilum

QuoteThere is also a difference between "the program works" as in "it renders what I expect" and: "the program does not generate any OpenGL errors".
I guess in some cases but I don't see the difference here. From the stacktrace it seems the error happens during glLinkProgram. The shaders are detached afterwards.

I'll leave a github link: https://github.com/ilumar589/LWJGLGatheredStuff

Thanks for the response!

KaiHH

Yeah, this is somewhat a problem with the trace mode, because for some methods, it does not trace the call when that call generated an error. This is for all calls that also return a return value.
But anyway, you still see the function that generated the error in the callstack of the error log.
But the problem is that you call glGetShaderi() with a program object id (to query the link status), however that function is only valid to be called with a shader object id/handle, NOT a program id/handle. See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetShader.xhtml
In order to query the program link status, you _must_ use glGetProgrami: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetProgram.xhtml

ilum

Oh, that was extremely stupid of me for not noticing. Thank you! Sorry for the time waste on such a trivial thing  :)

KaiHH

Sure, no problem. Always glad to help. I guess the morale of the story is: ALWAYS trust the output of LWJGLX/debug. If it says, you have an error, then you have an error. :D

ilum

Quote from: KaiHH on September 28, 2020, 20:42:13
Sure, no problem. Always glad to help. I guess the morale of the story is: ALWAYS trust the output of LWJGLX/debug. If it says, you have an error, then you have an error. :D
Yup