joruof / imviz

Pythonic bindings of imgui/implot for visualization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

imviz.autogui with None in list leads to runtime error

mertemba opened this issue · comments

The following code leads to a runtime error:

viz.autogui([None])

The error output is:

[...]
    viz.autogui([None])
  File ".../site-packages/imviz/autogui.py", line 15, in autogui_func
    return AutoguiContext(params=params).render(obj, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/imviz/autogui.py", line 241, in render
    res = self.render(obj[i], str(i))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/imviz/autogui.py", line 96, in render
    self.call_post_header_hooks(obj, name)
  File ".../site-packages/imviz/autogui.py", line 72, in call_post_header_hooks
    h(obj, name, self)
  File ".../site-packages/imviz/autogui.py", line 22, in list_item_context
    if viz.begin_popup_context_item():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: id != 0

Apparently this is due to this binding:

    m.def("begin_popup_context_item", [&](std::string label) {

        return ImGui::BeginPopupContextItem(
                label.empty() ? 0 : label.c_str());
    },
    py::arg("label") = "");

And calling ImGui::BeginPopupContextItem(0) leads to the error.

Changing the line in autogui.py to if viz.begin_popup_context_item("foo"): prevents the error.

Thanks for reporting that! Yeah, definitely buggy behavior.

It is not possible to get a context menu if we don't render an item before.
Since for None no item is rendered this error is triggered.
The implementation of begin_popup_context_item behaves correctly.

I've added a check in the respective autogui function. The fix will be included in 0.2.5.

Awesome, thank you for the timely fix!