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

Restoring layout from memory rearranges windows and sometimes crashes. #7705

Open
nikitablack opened this issue Jun 18, 2024 · 2 comments
Open
Labels
docking settings .ini persistance

Comments

@nikitablack
Copy link

nikitablack commented Jun 18, 2024

Version/Branch of Dear ImGui:

Version 1.90.5, Branch: docking

Back-ends:

Custom

Compiler, OS:

Ubuntu 20.04

Details:

I'm trying to implement the maximize <-> restore functionality, i.e. by clicking on a button I want the selected window to cover the complete viewport, and by clicking once again return it to a previous position. Here's the full source code for this:

static bool maximized{false};

// don't show if other window is maximized
if (!maximized) {
    ImGui::Begin("C", nullptr);
    ImGui::Text("CCCCCCCCCC");
    ImGui::End();
}

ImGuiWindowFlags flags = ImGuiWindowFlags_None;

if (maximized) {
    auto* viewport = ImGui::GetMainViewport();

    ImGui::SetNextWindowPos(viewport->WorkPos);
    ImGui::SetNextWindowSize(viewport->WorkSize);
    ImGui::SetNextWindowViewport(viewport->ID);

    flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove;
}

ImGui::Begin("D", nullptr, flags);

static std::vector<char> settings{};

if (ImGui::Button(!maximized ? "Maximize" : "Restore")) {
    if (!maximized) {
        size_t size{};
        auto s = ImGui::SaveIniSettingsToMemory(&size);
        settings.resize(size);

        memcpy(settings.data(), s, size);
    } else if (!settings.empty()) {
        ImGui::LoadIniSettingsFromMemory(settings.data());
        settings.clear();
    }
    maximized = !maximized;
}

ImGui::End();

The first problem with this is that the order of windows is not preserved if the windows are tabbed. I.e. before the maximizing the tabs are in CD order and after restoring it's DC.
The second problem is that with certain actions the application SOMETIMES crashes. I saw multiple different asserts, but one that is reproducible is the following:

  1. Dock a window to the right of another window.
  2. Maximize.
  3. Restore.
  4. Dock a window over the another window.
  5. Maximize
  6. Restore -> Crash.

output

@ocornut
Copy link
Owner

ocornut commented Jun 18, 2024

Can you try moving the LoadIniSettingsFromMemory() call to before NewFrame() ?

@ocornut ocornut added docking settings .ini persistance labels Jun 18, 2024
@nikitablack
Copy link
Author

Unfortunately, it's the same. Only IM_ASSERT fires now from another place.

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

No branches or pull requests

2 participants