Skip to content
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

[glfw] Early-out of GLFW WndProc hook if there's no backend data #7175

Closed
wants to merge 1 commit into from

Conversation

nicebyte
Copy link

If we happen to call glfwTerminate after destroying the ImGui context, the WndProc that ImGui installs still gets triggered, but there is no backend data at that time. This is a simple one-line fix that just early-outs if bd is NULL for whatever reason.

…down

If we happen to call  `glfwTerminate`  after destroying the ImGui context, the WndProc that ImGui installs still gets triggered, but there is no backend data at that time. This is a simple one-line fix that just early-outs if `bd` is NULL for whatever reason.
@PathogenDavid
Copy link
Contributor

Did you forget to call ImGui_ImplGlfw_Shutdown before destroying the context?

It's supposed to remove the WndProc hook, which means ImGui_ImplGlfw_WndProc shouldn't be getting called when there isn't an active context.

@nicebyte
Copy link
Author

Sorry, I should have checked before submitting the PR. ImGui_ImplGlfw_Shutdown was not being called. Feel free to close this.

@ocornut
Copy link
Owner

ocornut commented Dec 29, 2023

Tempted to add extra asserts in ImGui::DestroyContext() to check they the backend void* are cleared so this would be caught better. I’ll investigate this when I get back them.

ocornut added a commit that referenced this pull request Jan 3, 2024
@ocornut
Copy link
Owner

ocornut commented Jan 3, 2024

Added extra assets in ImGui::DestroyContext()->Shutdown() path: 33d18c5

@ocornut ocornut closed this Jan 3, 2024
@jdumas
Copy link
Contributor

jdumas commented Mar 12, 2024

Hi @ocornut. I'm having issues with this assert when there are multiple nested ImGui contexts in an application. When multiple ImGui contexts are nested, it is expected to destroy the inner-most contexts before calling ImGui_ImplGlfw_Shutdown (which in turn should still be called before shutting down the last, outermost ImGui context). Would you consider rolling back this change and turning it into a warning?

@jdumas
Copy link
Contributor

jdumas commented Mar 12, 2024

Alternatively, I can also manually set ImGui::GetIO().BackendPlatformUserData = ImGui::GetIO().BackendRendererUserData = nullptr; before destroying any inner context to workaround this assertion, so maybe it's ok to keep it as is...

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

Successfully merging this pull request may close these issues.

4 participants