Hello Guest

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

  • 6 Replies
  • 131 Views
*

Offline ilum

  • *
  • 10
[SOLVED]Weird behavior with lwjglx-debug-1.0.0.jar
« on: September 28, 2020, 19:23:06 »
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
Code: [Select]
[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:
Code: [Select]
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());
            }
        }
    }
« Last Edit: September 28, 2020, 20:42:51 by ilum »

*

Offline KaiHH

  • ****
  • 292
Re: Weird behavior with lwjglx-debug-1.0.0.jar
« Reply #1 on: September 28, 2020, 20:05:45 »
This error message:
Quote
GL_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?

*

Offline ilum

  • *
  • 10
Re: Weird behavior with lwjglx-debug-1.0.0.jar
« Reply #2 on: September 28, 2020, 20:26:18 »
Quote
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 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!

*

Offline KaiHH

  • ****
  • 292
Re: Weird behavior with lwjglx-debug-1.0.0.jar
« Reply #3 on: September 28, 2020, 20:31:42 »
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
« Last Edit: September 28, 2020, 20:40:03 by KaiHH »

*

Offline ilum

  • *
  • 10
Re: Weird behavior with lwjglx-debug-1.0.0.jar
« Reply #4 on: September 28, 2020, 20:41:18 »
Oh, that was extremely stupid of me for not noticing. Thank you! Sorry for the time waste on such a trivial thing  :)

*

Offline KaiHH

  • ****
  • 292
Re: Weird behavior with lwjglx-debug-1.0.0.jar
« Reply #5 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

*

Offline ilum

  • *
  • 10
Re: Weird behavior with lwjglx-debug-1.0.0.jar
« Reply #6 on: September 28, 2020, 20:43:35 »
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