我正在尝试设置 ImGui 来制作一些应用程序,但是我无法让它工作。我从 GitHub,https://github.com/ocornut/imgui安装了.h
和文件,并按照说明允许项目编译,它确实如此。但是在 Windows 和 Linux 上(我都试过了),它会吐出一个运行时错误,(停止响应 Windows,分段错误(核心转储)Linux)。这是发布的示例代码,.cpp
#include "imgui.h"
int main()
{
// Create a window called "My First Tool", with a menu bar.
ImGui::Begin("My First Tool", &my_tool_active, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */ }
if (ImGui::MenuItem("Save", "Ctrl+S")) { /* Do stuff */ }
if (ImGui::MenuItem("Close", "Ctrl+W")) { my_tool_active = false; }
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
// Edit a color (stored as ~4 floats)
ImGui::ColorEdit4("Color", my_color);
// Plot some values
const float my_values[] = { 0.2f, 0.1f, 1.0f, 0.5f, 0.9f, 2.2f };
ImGui::PlotLines("Frame Times", my_values, IM_ARRAYSIZE(my_values));
// Display contents in a scrolling region
ImGui::TextColored(ImVec4(1,1,0,1), "Important Stuff");
ImGui::BeginChild("Scrolling");
for (int n = 0; n < 50; n++)
ImGui::Text("%04d: Some text", n);
ImGui::EndChild();
ImGui::End();
return 0;
}
my_tool_active
现在这段代码由于and无法编译my_color
,所以我在代码之前添加了这两行ImGui::Begin()
:
bool my_tool_active = true;
float my_color[4] = {0.5, 0.5, 0.5, 1};
所以现在当我编译和运行时,它会ImGui::Begin()
在那个阶段崩溃。我在一个小得多的示例中尝试过它,它只是ImGui::Begin()
andImGui::End()
并在其周围放置了 print 语句,它表明它从未完成执行Begin()
.