DefinitionsObserver firing as many times as there are models opened on Mac

Hi,
We’re encountering an unexpected behavior when using DefinitionsObserver and copy-pasting objects between models.

Context: In our extension, we need to watch for the users copying objects between models and react appropriately when their definitions contain some data from our extension. To do so, we use DefinitionsObserver::onComponentAdded.

Expected behavior: the observer should fire once for the model in which the object is copied.

Issue: the observer is fired several times, once for each opened model. We’re having users reporting bugs when copy-pasting objects and this might be related. This happens from SU 2017 to 2020.

Reproducing the bug:

Use the following minimal extension: https://gist.github.com/merwaaan/26a9d10d3f06b36858dbcb8c8cd14cd1

  • create a plane
  • make it a group
  • copy
  • create a new model
  • paste (note: the observer is fired when typing ctrl-v and then again when clicking to validate the copy)

The Ruby console shows something like

attaching observer to the startup model 60

new model 3065
attaching observer to new model 3065
definition 5701 added to model 3065: 1 times
definition 5701 added to model 3065: 2 times

new model 5740
attaching observer to new model 5740
definition 8376 added to model 5740: 1 times
definition 8376 added to model 5740: 2 times
definition 8376 added to model 5740: 3 times

Thanks for your help.

1 Like

The place to log bugs is:

Dully noted!

I’m still interested in feedback from other users or the developers to make sure that the provided minimal example isn’t bugged or if we’re improperly using the API before filing a format bug report :wink:

1 Like