我在我的项目中使用Nanogui,我试图在窗口中创建按钮,然后关闭该窗口。我的功能看起来像:
void foo(const std::unique_ptr<nanogui::Screen>& screenPtr) {
serverStatusIsOpen = true;
auto *window = new Window(screenPtr.get(), "Test window");
window->setPosition(Vector2i(100, 100));
auto *layout = new GridLayout(Orientation::Vertical, 1, Alignment::Middle, 15, 5);
window->setLayout(layout);
auto *b = new Button(window, "Close");
b->setCallback([&window, this](){
serverStatusIsOpen = false;
//close window
});
this->screen->performLayout();
}
如果我添加
window->setVisible(false);
this->screen->performLayout();
或
this->screen->removeChild(window);
this->performLayout();
应用程序崩溃。有什么选项可以安全关闭应用程序屏幕内的窗口而不会崩溃?