Hi all,
related to this topic , i’ve basically this problem. Here’s basic code:
struct KeyInterceptor : Widget {
// ...
}
MyWidget(My *module) : ModuleWidget(module) {
// ...
// key interceptor
Vec keyInterceptorTargetRect{pModulePlot->kDragAreaWidth, pModulePlot->kDragAreaHeight};
keyInterceptor = new KeyInterceptor(module, this, pModulePlot, keyInterceptorTargetRect);
APP->scene->addChildAbove(keyInterceptor, APP->scene->rackScroll);
}
~MyWidget() {
if (keyInterceptor) {
APP->scene->removeChild(keyInterceptor);
delete keyInterceptor;
}
}
and happens that when I close Rack, it going in errors, showing to me:
Assertion failed: child->parent == this, file src/widget/Widget.cpp, line 221
make: *** [Makefile:118: run] Error 3
What’s wrong in your opinions? I basically use Rack API to add/remove a child.
Thanks for any tips.
Bloodbat
(Bloodbat)
May 28, 2025, 8:45am
2
I may be wrong; but I believe parents own children… that is: parents manage their children.
You could try removing the manual removeChild and destructor, see if it crashes and see if it leaks.
Honestely I would trust the code by the master @stoermelder , which removeChild as well in his destructor.
Ben: do you catch the same error when closing Rack? (after search/show the module on Rack Library).
No, I get no error, but I’m using APP->scene->rack
as parent. I’m not sure, if it makes any difference.
which line in your code is line 221?
I think this is the issue, APP->scene->rackScroll
is a RackScrollWidget
which is different to a RackWidget
is there a reason you want to add your widget to the scroll widget rather than the rack widget?
If you want to add a widget to capture key input; this works for me:
APP->scene->rack->addChild(keyInterceptor);
//---
// destructor
APP->scene->rack->removeChild(keyInterceptor);
delete keyInterceptor;
edit: actually, i think the issue is simply that you are using addChildAbove
instead of addChild
, this makes keyInterceptor
a sibling to APP->scene->rackScroll
not a child of it.
1 Like
pachde
(Paul Dempsey)
May 28, 2025, 3:09pm
7
Sometimes it’s better to use widget->requestDelete()
instead of parent->removeChild(widget)
(then you don’t need to worry about who the parent is).
THIS! In fact using add/remove child seems to work well.
Can’t do ->rack-> since I need to also intercept ALT button (which is ignored with ->rack->).
I’m play with it and let me see. Thanks