Ports added to child component disappear when Rack restarts

I/O connections disappear after restarting Rack when addInput called outside ModuleWidget constructor.

In the constructor of my ModuleWidget class, instead of adding inputs directly, I create instances of another Widget, pass a pointer to those instances…

myModuleWidget::myModuleWidget(myModule *module)
	for(int i=0;i<4;i++)
	SourceParametersWidget *pw = new SourceParametersWidget(this,...);

…and add the inputs there:

SourceParametersWidget(MyModuleWidget *myModuleWidget,...)
	Module *module = myModuleWidget->module;
	addInput(createInput<R4Port>(Vec(...), module, ...));

Unfortunately, when I connect something to these inputs/outputs, the connections disappear when Rack is closed and reopened.

What am I doing wrong? Thanks!

P.S.: It worked with v 0.6.2

My guess is that rack only parse the ModuleWidget, when serializing/deserializing cable connections, not child widgets.

Not sure if there’s an elegant way of workaround this.

I found the answer… it’s simple:

In SourceParametersWidget(...), it must be

myModuleWidget->addInput(createInput<R4Port>(Vec(...), module, ...));

, not just

addInput(createInput<R4Port>(Vec(...), module, ...));

Without myModuleWidget->, the inputs are not added to myModuleWidget but to mySourceParametersWidget where Rack is of course not looking for them.

Unfortunately, now the layout is messed up but that should be easy to correct.

That’s why I said I was not sure there was an elegant workaround :wink:

Maybe you can try this way :

Input* input = createInput(...);

Though I wouldn’t really advise to do so not sure if it’s a stable API approach

Thanks a lot! I am now simply passing the future position of the child widget as a Vec parameter and add it to the individual offsets. Done!

I only fear that now the inputs are not part of the child widget any more. In my special case here it is not a problem but it might become a problem as soon as child widgets are layered on top of each other. Then I might need to have a look at your approach again.

How would that compile since addInput is only defined on ModuleWidget?

In the old (now discarded) code, SourceParametersWidget iherited from ModuleWidget. For some reason, this worked with 0.6.2.

That makes me want to curl into a fetal position and delete the Rack project.

1 Like

For the sake of completeness: What is the best way to add ports to a child component? Is that possible/‘permittet’ at all? Some ports could be active but not visible… are cables only shown if both ports of the connection are visible and hidden otherwise?

Are there any modules yet in which the visibility of ports changes at runtime?

There is no supported way that is guaranteed not to break in a minor revision of Rack. In v1 you can implement the following hack.

PortWidget* inputWidget = ...;

However, when you implement hacks, it is a courtesy to test and fix them quickly when they break.

Thanks, I’ll try that!