Open jzrake opened 6 years ago
You should capture b
and remove it explicitly:
b->setCallback([this, b]() { removeChild(b); });
For python you'll need to be more explicit. Untested, but something like this should work
b = nanogui.Button(self, "Click to remove me")
b.setCallback(lambda: self.removeChild(b))
The implementation differences are here:
Basically, you should prefer the explicit Widget *
version. IIRC the callback is executed twice (put some print statements in to confirm), once for push and once for release? If so, then the second one is where the segfault comes from, because it was already removed in the first execution.
UhOh. I just added that and tested, and if you do the explicit capture of b
then you'll get a segfault later. First click removes it, but then if you click in the same spot you'll get a segfault...
Attempting to remove a button from its parent on click results in a seg fault:
This appears to be a bug, because according to
button.cpp
, the button should be retained until after any callbacks are finished: