I create an instance of
const widget = vtkImageCroppingWidget.newInstance();.
I attach a callback to its cropping planes state.
After a while I delete this widget by calling
At some point I create another cropping widget in another place in the system, and while interacting with it, in addition to its new callback, the old callback is also called.
The question - is it by design that all instances of the same widget class share the state and the callbacks?
All widgets created from the same factory will share the state. Your
widget variable is actually a widget factory, and
widgetManager.addWidget(widget) will create an instance of the widget for that particular renderer. This allows for multiple renderers to render the same widget state.
You will need to take the return from
subscription = widgetState.onModified(...) and call
subscription.unsubscribe() to remove the old callback.
Thanks for your reply!
Sorry, I haven’t made myself clear.
The widget created later was created by another widget factory:
widgetFactory1 = vtkImageCroppingWidget.newInstance();
widgetFactory2 = vtkImageCroppingWidget.newInstance();
Then a widget created by
widgetFactory2 invokes the callback that was attached to
Seems like a bug, or I don’t understand something about the architecture.
That indeed should not be occurring. I will take a look.