Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

ImGui Крашится

  • Автор темы Автор темы Porches
  • Дата начала Дата начала
Участник
Участник
Статус
Оффлайн
Регистрация
28 Дек 2018
Сообщения
540
Реакции
215
Ку всем, пишу новое меню софту и почему то некоторые виджеты при взаимодействии крашат игру. Некоторые чекбоксы и HotKey. При чем не все, а только несколько штук, почему хз. Вот кусок меню крашущий.

Код:
Expand Collapse Copy
void MiscTab()
{
    ImGui::Spacing();
    ImGui::Spacing();

    static int misc_subtab = 1;

    ImGui::SameLine();
    ImGui::SameLine();
    if (ImGui::Button("General", ImVec2(300, 25))) misc_subtab = 1;
    ImGui::SameLine();
    if (ImGui::Button("Other", ImVec2(300, 25))) misc_subtab = 2;

    if (misc_subtab == 1)
    {
        ImGui::SameLine();
        ImGui::Checkbox("Anti-Untrusted", g_Options.misc_aut);
        ImGui::Checkbox("Bunny Hop", g_Options.misc_bhop);
        ImGui::Checkbox("Auto Strafe", g_Options.misc_autostrafe);
        ImGui::Checkbox("Spectator List", g_Options.misc_spectator_list);
        ImGui::Checkbox("Auto Accept", g_Options.misc_autoaccept);
        ImGui::Checkbox("Edge Jump", g_Options.misc_edge_jump);
        ImGui::Checkbox("Show Ranks", g_Options.misc_showranks);
    }
    else
    {
        ImGui::SameLine();
        ImGui::Checkbox("FOV Changer", g_Options.misc_fov_changer);
        if (g_Options.misc_fov_changer)
        {
            ImGui::PushItemWidth(150);
            ImGui::SliderInt("Viewmodel FOV", g_Options.viewmodel_fov, 68, 120);
            ImGui::SliderInt("Override FOV", g_Options.overridefov, 90, 150);
        }
        ImGui::Spacing();
        if (!g_Options.misc_aut)
        {
            ImGui::Checkbox("Fakeduck", g_Options.misc_fakeduck);
            ImGui::PushItemWidth(150);
            ImGui::SliderInt("Ticks", g_Options.misc_fakeduck_ticks, 1, 16);
            ImGui::Hotkey("Key", g_Options.misc_fakeduck_key, ImVec2(150, 25));
        }
    }
}
Крашит все что во второй части.
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
после каждого pushitemwidth должен быть закрывающий popitemwidth
 
Код:
Expand Collapse Copy
bool ImGui::Hotkey(const char* label, int* k, const ImVec2& size_arg)
{
    ImGuiWindow* window = ImGui::GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    ImGuiIO& io = g.IO;
    const ImGuiStyle& style = g.Style;

    const ImGuiID id = window->GetID(label);
    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImVec2 size = ImGui::CalcItemSize(size_arg, ImGui::CalcItemWidth(), label_size.y + style.FramePadding.y*2.0f);
    const ImRect frame_bb(window->DC.CursorPos + ImVec2(label_size.x + style.ItemInnerSpacing.x, 0.0f), window->DC.CursorPos + size);
    const ImRect total_bb(window->DC.CursorPos, frame_bb.Max);

    ImGui::ItemSize(total_bb, style.FramePadding.y);
    if (!ImGui::ItemAdd(total_bb, id))
        return false;

    const bool focus_requested = ImGui::FocusableItemRegister(window, g.ActiveId == id, false);
    const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent);
    const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;

    const bool hovered = ImGui::ItemHoverable(frame_bb, id);

    if (hovered) {
        ImGui::SetHoveredID(id);
        g.MouseCursor = ImGuiMouseCursor_TextInput;
    }

    const bool user_clicked = hovered && io.MouseClicked[0];

    if (focus_requested || user_clicked) {
        if (g.ActiveId != id) {
            // Start edition
            memset(io.MouseDown, 0, sizeof(io.MouseDown));
            memset(io.KeysDown, 0, sizeof(io.KeysDown));
            *k = 0;
        }
        ImGui::SetActiveID(id, window);
        ImGui::FocusWindow(window);
    }
    else if (io.MouseClicked[0]) {
        // Release focus when we click outside
        if (g.ActiveId == id)
            ImGui::ClearActiveID();
    }

    bool value_changed = false;
    int key = *k;

    if (g.ActiveId == id) {
        for (auto i = 0; i < 5; i++) {
            if (io.MouseDown[i]) {
                switch (i) {
                case 0:
                    key = VK_LBUTTON;
                    break;
                case 1:
                    key = VK_RBUTTON;
                    break;
                case 2:
                    key = VK_MBUTTON;
                    break;
                case 3:
                    key = VK_XBUTTON1;
                    break;
                case 4:
                    key = VK_XBUTTON2;
                    break;
                }
                value_changed = true;
                ImGui::ClearActiveID();
            }
        }
        if (!value_changed) {
            for (auto i = VK_BACK; i <= VK_RMENU; i++) {
                if (io.KeysDown[i]) {
                    key = i;
                    value_changed = true;
                    ImGui::ClearActiveID();
                }
            }
        }

        if (IsKeyPressedMap(ImGuiKey_Escape)) {
            *k = 0;
            ImGui::ClearActiveID();
        }
        else {
            *k = key;
        }
    }

    // Render
    // Select which buffer we are going to display. When ImGuiInputTextFlags_NoLiveEdit is Set 'buf' might still be the old value. We Set buf to NULL to prevent accidental usage from now on.

    char buf_display[64] = "None";

    ImGui::RenderFrame(frame_bb.Min, frame_bb.Max, ImGui::GetColorU32(ImVec4(0.20f, 0.25f, 0.30f, 1.0f)), true, style.FrameRounding);

    if (*k != 0 && g.ActiveId != id) {
        strcpy_s(buf_display, KeyNames[*k]);
    }
    else if (g.ActiveId == id) {
        strcpy_s(buf_display, "Press a key");
    }

    const ImRect clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); // Not using frame_bb.Max because we have adjusted size
    ImVec2 render_pos = frame_bb.Min + style.FramePadding;
    ImGui::RenderTextClipped(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding, buf_display, NULL, NULL, style.ButtonTextAlign, &clip_rect);
    //RenderTextClipped(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding, buf_display, NULL, NULL, GetColorU32(ImGuiCol_Text), style.ButtonTextAlign, &clip_rect);
    //draw_window->DrawList->AddText(g.Font, g.FontSize, render_pos, GetColorU32(ImGuiCol_Text), buf_display, NULL, 0.0f, &clip_rect);

    if (label_size.x > 0)
        ImGui::RenderText(ImVec2(total_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), label);

    return value_changed;
}
Дефолт в принципе, ты не знаешь кстати как фиксить, то когда я нажимаю на один, активируются все HotKey в текущем табе.
 
Код:
Expand Collapse Copy
bool ImGui::Hotkey(const char* label, int* k, const ImVec2& size_arg)
{
    ImGuiWindow* window = ImGui::GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    ImGuiIO& io = g.IO;
    const ImGuiStyle& style = g.Style;

    const ImGuiID id = window->GetID(label);
    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImVec2 size = ImGui::CalcItemSize(size_arg, ImGui::CalcItemWidth(), label_size.y + style.FramePadding.y*2.0f);
    const ImRect frame_bb(window->DC.CursorPos + ImVec2(label_size.x + style.ItemInnerSpacing.x, 0.0f), window->DC.CursorPos + size);
    const ImRect total_bb(window->DC.CursorPos, frame_bb.Max);

    ImGui::ItemSize(total_bb, style.FramePadding.y);
    if (!ImGui::ItemAdd(total_bb, id))
        return false;

    const bool focus_requested = ImGui::FocusableItemRegister(window, g.ActiveId == id, false);
    const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent);
    const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;

    const bool hovered = ImGui::ItemHoverable(frame_bb, id);

    if (hovered) {
        ImGui::SetHoveredID(id);
        g.MouseCursor = ImGuiMouseCursor_TextInput;
    }

    const bool user_clicked = hovered && io.MouseClicked[0];

    if (focus_requested || user_clicked) {
        if (g.ActiveId != id) {
            // Start edition
            memset(io.MouseDown, 0, sizeof(io.MouseDown));
            memset(io.KeysDown, 0, sizeof(io.KeysDown));
            *k = 0;
        }
        ImGui::SetActiveID(id, window);
        ImGui::FocusWindow(window);
    }
    else if (io.MouseClicked[0]) {
        // Release focus when we click outside
        if (g.ActiveId == id)
            ImGui::ClearActiveID();
    }

    bool value_changed = false;
    int key = *k;

    if (g.ActiveId == id) {
        for (auto i = 0; i < 5; i++) {
            if (io.MouseDown[i]) {
                switch (i) {
                case 0:
                    key = VK_LBUTTON;
                    break;
                case 1:
                    key = VK_RBUTTON;
                    break;
                case 2:
                    key = VK_MBUTTON;
                    break;
                case 3:
                    key = VK_XBUTTON1;
                    break;
                case 4:
                    key = VK_XBUTTON2;
                    break;
                }
                value_changed = true;
                ImGui::ClearActiveID();
            }
        }
        if (!value_changed) {
            for (auto i = VK_BACK; i <= VK_RMENU; i++) {
                if (io.KeysDown[i]) {
                    key = i;
                    value_changed = true;
                    ImGui::ClearActiveID();
                }
            }
        }

        if (IsKeyPressedMap(ImGuiKey_Escape)) {
            *k = 0;
            ImGui::ClearActiveID();
        }
        else {
            *k = key;
        }
    }

    // Render
    // Select which buffer we are going to display. When ImGuiInputTextFlags_NoLiveEdit is Set 'buf' might still be the old value. We Set buf to NULL to prevent accidental usage from now on.

    char buf_display[64] = "None";

    ImGui::RenderFrame(frame_bb.Min, frame_bb.Max, ImGui::GetColorU32(ImVec4(0.20f, 0.25f, 0.30f, 1.0f)), true, style.FrameRounding);

    if (*k != 0 && g.ActiveId != id) {
        strcpy_s(buf_display, KeyNames[*k]);
    }
    else if (g.ActiveId == id) {
        strcpy_s(buf_display, "Press a key");
    }

    const ImRect clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); // Not using frame_bb.Max because we have adjusted size
    ImVec2 render_pos = frame_bb.Min + style.FramePadding;
    ImGui::RenderTextClipped(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding, buf_display, NULL, NULL, style.ButtonTextAlign, &clip_rect);
    //RenderTextClipped(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding, buf_display, NULL, NULL, GetColorU32(ImGuiCol_Text), style.ButtonTextAlign, &clip_rect);
    //draw_window->DrawList->AddText(g.Font, g.FontSize, render_pos, GetColorU32(ImGuiCol_Text), buf_display, NULL, 0.0f, &clip_rect);

    if (label_size.x > 0)
        ImGui::RenderText(ImVec2(total_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), label);

    return value_changed;
}
Дефолт в принципе, ты не знаешь кстати как фиксить, то когда я нажимаю на один, активируются все HotKey в текущем табе.
Не ставь одинаковый лейбл. Тогда не будут все сразу активироваться.
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Во правых не вижу у тебя popitemwidth, во вторых, чтобы у тебя не активировались сразу все хоткеи, не пиши везде Key, из-за одинакового названия они могут все сразу работать
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
каво, у него в коде только один вызов imgui::hotkey
Он лишь скинул часть крашущего кода. Да, в нём один хоткей. Но он то говорит что сразу все хоткеи активируются -> их больше
 
Во правых не вижу у тебя popitemwidth, во вторых, чтобы у тебя не активировались сразу все хоткеи, не пиши везде Key, из-за одинакового названия они могут все сразу работать
Я добавил, но крашит чекбокс именно
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Видно сразу, в тупую скопировал. Стек вызовов хоть прикрепил бы, а не просто код из куска таба
 
мб проблема в коде, а не меню?
Так а схерали именно этот чекбокс крашит, если я поставлю его в другое место он опять таки крашит. Дебаггер говорит об отсутствии символов
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Так а схерали именно этот чекбокс крашит, если я поставлю его в другое место он опять таки крашит. Дебаггер говорит об отсутствии символов
Ало, мб у тебя крашит функция сама фова?
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Назад
Сверху Снизу