SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

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

Open merwaaan opened 4 years ago

merwaaan commented 4 years ago
  1. SketchUpVersion: 2017 to 2020
  2. OS Platform: Mac

Describe briefly what you are doing and what is happening.

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.

Describe what the expected result is.

The observer should fire once for the model in which the object is copied.

What happens

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.

Reprodusible code

https://gist.github.com/merwaaan/26a9d10d3f06b36858dbcb8c8cd14cd1

Steps:

The Ruby console will show 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
thomthom commented 4 years ago

I can reproduce. (Silly observers... they are the bane of me.)

sketchupbot commented 4 years ago

SU-46005