8000 Optional GLFW termination on library side if client code initializes it. · Issue #2687 · glfw/glfw · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optional GLFW termination on library side if client code initializes it. #2687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
abhi-k9 opened this issue Feb 12, 2025 · 4 comments
Open

Comments

@abhi-k9
Copy link
abhi-k9 commented Feb 12, 2025

Hi,

I have a library that uses GLFW to setup the context for OpenGL offscreen rendering. At the moment, I initialize and terminate the it around my API calls.

However, the client code could also be depending on GLFW and needs it to remain in a initialized state after completion of my API functions, i.e. my library should not terminate GLFW if the client code initialized GLFW for its own purposes.

I was thinking of checking if it was already initialized upon entry to my API and if so not terminate, but #2036 mentions this is not possible as of now, and attempts to add reference counting have been hanging for a long time #2070.

Are there any workarounds for this use case?

@abhi-k9 abhi-k9 changed the title Handling GLFW termination on library side. Optional GLFW termination on library side if client code initializes it. Feb 12, 2025
@israfiel-a
Copy link

Have you tried using flags? Perhaps a function parameter to one of your library methods? This seems like more of a client-issue rather than a GLFW one.

@abhi-k9
Copy link
Author
abhi-k9 commented Mar 6, 2025

I think that would pass the burden up the client stack while the core issue remains. For example, client C depends on my library L1 and also another library L2.

If L2 internally initializes GLFW without notifying C, there is no way C can pass on that information to me, i.e. L1. If I then terminate GLFW thinking no one else is using it that would break L2.

This information, whether GLFW is initialized has to be centralized and the best place is GLFW itself following KISS principle. I don't see any downsides to having a glfwIsInitialized() function.

Thanks.

@israfiel-a
Copy link

That's a valid point. It would also be relatively simple to implement. I'd suggest patching the library yourself until this issue can be properly reviewed by a maintainer. For example, you could add a function signature (i.e. int glfwIsinitialized(void)) to the GLFW header (GLFW.h), and then in src/init.c, you could add the following code:

int glfwIsInitialized(void) {
    return _glfw.initialized;
}

I've not compiled, but I am 99% sure the following code would work perfectly for your purposes.

@abhi-k9
Copy link
Author
abhi-k9 commented Mar 9, 2025

I have created a pull request for the patch if it helps.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0