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

Issue with ImGui_ImplMetal_Shutdown - Crashes inside ImGui_ImplMetal_DestroyFontsTexture #7530

Closed
werewolf2188 opened this issue Apr 25, 2024 · 2 comments

Comments

@werewolf2188
Copy link

werewolf2188 commented Apr 25, 2024

Version/Branch of Dear ImGui:

docking

Back-ends:

imgui_impl_metal.mm

Compiler, OS:

Xcode

Full config/build information:

No response

Details:

Crash inside ImGui_ImplMetal_DestroyFontsTexture:

While using ImGui with metal, I noticed that it was crashing during the shutdown. That's because, inside ImGui_ImplMetal_Shutdown, line 160, the code io.BackendRendererUserData = nullptr; is making the function ImGui_ImplMetal_GetBackendData to return nullptr, and thus, all subsequent functions (to destroy objects and fonts) are going to crash.

THERE IS already a function to clean the io.BackendRendererUserData and it's called ImGui_ImplMetal_DestroyBackendData

I can make a PR if needed, but this is going to crash for whoever uses it.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

void ImGui_ImplMetal_Shutdown()
{
    ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
    IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
    ImGui_ImplMetal_ShutdownPlatformInterface();

    ImGuiIO& io = ImGui::GetIO();
    io.BackendRendererName = nullptr;
//    io.BackendRendererUserData = nullptr; // <-- this is going to crash whatever function calls ImGui_ImplMetal_GetBackendData later.
    io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports);
    ImGui_ImplMetal_DestroyDeviceObjects();
    ImGui_ImplMetal_DestroyBackendData();
}
@ocornut
Copy link
Owner

ocornut commented Apr 26, 2024

Hello,
This is not how the function looks on latest:

void ImGui_ImplMetal_Shutdown()
{
    ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData();
    IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
    ImGui_ImplMetal_ShutdownPlatformInterface();
    ImGui_ImplMetal_DestroyDeviceObjects();
    ImGui_ImplMetal_DestroyBackendData();

    ImGuiIO& io = ImGui::GetIO();
    io.BackendRendererName = nullptr;
    io.BackendRendererUserData = nullptr;
    io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasViewports);
}

This was fixed by 70cca1e in April 2023 so I assume you are using an old version?

@ocornut ocornut closed this as completed Apr 26, 2024
@werewolf2188
Copy link
Author

@ocornut Yeah, I haven't updated for a while, and I'm also using a fork. Thank you for letting me know.

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

No branches or pull requests

2 participants