-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Check if GLFW has been initialized #2036
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
Comments
The two first lines of if (_glfw.initialized)
return GLFW_TRUE; Same with GLFWAPI void glfwTerminate(void)
{
if (!_glfw.initialized)
return;
terminate();
} |
I know I've been there, but this does not solve my problem. In my library I have multiple rendering facilities based on GLFW. In this case it is sometimes convenient to perform a test like |
If the client is not using GLFW, will your library initialize and terminate GLFW several times during the execution of the program? So each of your rendering functions will begin with |
Yes and no. I have a GL window that is used for online rendering and in 99.9% of the cases is the function that will initialize and terminate GLFW. In addition to this I have an offline rendering facility, based on |
Yup, this or something like it could be useful to have. |
Hi, some time ago I needed this for a unittest, but after looking at the GLFW source I found a solution without needing to make a feature request. I wrote this function as a temporary way to check this:
|
In case of OPs problem, one could argue the problem is that GLFW is broken and should not just maintain a bool to know if it is initialized, but have a reference count and only terminate when the reference count gets to 0. With that change it would work for him automatically without testing and maintaining his own bool. For another example why the current behaviour is bad: Just imagine a long running program initializing GLFW once at start, using it the whole runtime before and after using a plug-in or library that initializes GLFW only for a moment when needed and terminates it ASAP. The program would then not have an initialized GLFW anymore. |
i made a pull request attempting to fix the issue. |
I added another pull request with the code I wrote for the solution I suggested. If it would be merged, the problem should go away automatically without additional user code for the thread opener and other people with similar scenarios. |
I have run into a use case where I have a plugin that adds GLFW support to an application at runtime, but there are other plugins in the environment that may also add GLFW support. It would be great to check for initialization as to know if I need to terminate it, or if some other piece of code is going to do it (AKA, already initialized it before my code). I would say for now, I like both implementations #2065 and #2070, and would like to see both merged. Perhaps in the meantime while #2070 is being discussed it would be great to get #2065 merged. |
@tlf30 On the kanban board under "Projects" you can see there is so many more pressing issues triaged as "Always", "Urgent" and "Now", while this is triaged as a non-pressing "enhancement" waiting for its time in "Todo" without the MRs having been added to the kanban card. I do not expect this to get looked at any soon, although I would classify this issue as a low hanging fruit. |
Hi,
I maintain a library that exposes rendering facilities internally implemented with GLFW. I'd like to handle the calls to
glfwInit()
andglfwTerminate()
directly from within the library, but since there are multiple entry points it would be necessary to know if the environment had already been initialized or not.I've seen that internally these macros implement similar checks
_GLFW_REQUIRE_INIT()
_GLFW_REQUIRE_INIT_OR_RETURN(NULL)
but they are not accessible from outside GLFW and I could not find an alternative public call in the API.
A similar question was posted long time ago here, but I am not aware of any improvement to this end. Do you think it would be possible to add a boolean function like
glfwIsInitialized()
? It is true that one could obtain the desired effect by externally storing the GLFW state in an external boolean variable, but in my specific case I'd rather avoid it because the library does not maintain an internal state.Thanks!
The text was updated successfully, but these errors were encountered: