LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: jakethesnake on January 03, 2021, 08:42:00

Title: [Bug] Other software producing errors in my context?
Post by: jakethesnake on January 03, 2021, 08:42:00
It seems like many screen recording devices, but also some other software keep crashing my app by producing openGL errors.

[LWJGL] OpenGL debug message
                ID: 0x500
                Source: API
                Type: ERROR
                Severity: HIGH
                Message: GL_INVALID_ENUM error generated. Operation is not valid from the core profile.


I realize this is no fault of LWJGL, but what is the preferred workaround? I like keeping my code clean, by not accepting any errors, but this makes it impossible.

A way of reproducing is just trying to stream an app with discord. I'm using opengl 3.3 core profile, maybe that's important.
Title: Re: [Bug] Other software producing errors in my context?
Post by: Source_of_Truth on January 04, 2021, 13:39:18
Well, it would certainly be interesting why exactly a GL_INVALID_ENUM is created there. More context is needed.

A good way to debug this might be to enable the debugging context:
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
Title: Re: [Bug] Other software producing errors in my context?
Post by: jakethesnake on January 07, 2021, 08:27:09
Here are some examples:

LWJGL] OpenGL debug message
        ID: 0x502
        Source: API
        Type: ERROR
        Severity: HIGH
        Message: GL_INVALID_OPERATION error generated. Function glPushAttrib is deprecated and not available in preview contexts.
[LWJGL] OpenGL debug message
        ID: 0x502
        Source: API
        Type: ERROR
        Severity: HIGH
        Message: GL_INVALID_OPERATION error generated. Function glPopAttrib is deprecated and not available in preview contexts.


I'm not calling these functions in my app. Somehow the external apps must hijack my context and do these things?

Examples of capture software that breaks stuff:

Discord, EaseUS RecExperts and oCam

Any way to fix this? Or just start polling and ignoring errors?

Here are some from discord:

[LWJGL] OpenGL debug message
                ID: 0x500
                Source: API
                Type: ERROR
                Severity: HIGH
                Message: GL_INVALID_ENUM error generated. Operation is not valid from the core profile.
[LWJGL] OpenGL debug message
                ID: 0x502
                Source: API
                Type: ERROR
                Severity: HIGH
                Message: GL_INVALID_OPERATION error generated. The required buffer is missing.
[LWJGL] OpenGL debug message
                ID: 0x502
                Source: API
                Type: ERROR
                Severity: HIGH
                Message: GL_INVALID_OPERATION error generated. The required buffer is missing.

Title: Re: [Bug] Other software producing errors in my context?
Post by: jakethesnake on April 25, 2021, 09:46:39
I've managed to find the culprit (at least where the opengl error is generated, and it's in glfwSwapBuffers

GlHelper.checkErrors();
glfwSwapBuffers(window);
GlHelper.checkErrors(); <- causes GL_INVALID_OPERATION

This is when streaming through discord.

Now I need to find out what's causing it.It doesn't happen with the "hello world example", even when adding my window hints. I've littered opengl error checks after basically every opengl operation in my rendering code and it's clean.

Some hints/pointers on how/why glfwSwapBuffers does this would be very helpful.
Title: Re: [Bug] Other software producing errors in my context?
Post by: jakethesnake on April 25, 2021, 10:30:18
I found the culprit!  ;D

I was rendering everything to an offline FBO, then at the end of the render call made a blit to the default FB, so called offline rendering.

When blitting, I put the default FB as draw, and the FBO as read. I did not change back until after glfwSwapBuffers.

So, my theory is that discord hooks itself into the swapbuffers call and when it's triggered, it reads the FB bound to read, which was my FBO, and that didn't work well.

glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

did the trick after the blit. Can be worth mentioning that swapbuffers can have this behaviour.

Now I'm only left with

[LWJGL] OpenGL debug message
   ID: 0x500
   Source: API
   Type: ERROR
   Severity: HIGH
   Message: GL_INVALID_ENUM error generated. Operation is not valid from the core profile.

Which happens the second I start streaming. I can't catch it with glGetErrors though, it's vanished.

Removing these hints solves that problem:

      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

It is not enough to simply remove the GLFW_OPENGL_CORE_PROFILE one, even though the error output suggests it.

I'm not sure why I specify these hints. I guess it's because I'm using >= 3.3 features, but other from that I'm not sure about the benefit, I just want my app to be as compatible as possible. I can check through glCapabilities if 3.3 is supported.

Ah, now I remember, to make it work on Mac...