I see a delay in getting view observer events in SU2019.
For some reason the observer doesn’t trigger immediately, but fires up after entering/leaving a group or component.
It looks like something is holding up all the onViewChanged() events and spilling them out afterwards.
Does anyone see similar thing? I set the view observer from C Ruby extension - I am calling Ruby function from there.
When I created a minimal sample in pure Ruby everything works fine, so I think it has to do with the call from C.
It is Win. Mac works fine.
It looks I will have to modify the C extensions example to replicate the issue to share it here.
I call AddObservers() Ruby function from C using:
rb_eval_string(“AddObservers()”);
In the Ruby function I do:
Sketchup.active_model.active_view.add_observer(MyViewObs.new)
Is there an open operation? Since SU2016 observer event’s that happens during an operation is deferred until the end of the operation.
Can you provide a complete example to repro? At least the complete source code. (We can insert the C code into the Ruby C Extension example we have on github)
I have to spend more time on it to tell what is going on. Could it be related to linking with sketchup.lib? I have made a lot of changes in the code to migrate from C++ to C SDK, but I didn’t touch the observers in the process.
I also noticed that when I added a “minimal view observer” plugin, then my original function also started to receive the event immediately.
While chasing the issue, I found one thing that may be related.
I really do not understand why C API copies a behavior of Ruby function for getting an attribute dictionary. A “getter” should be just a function that gets something and does not create it when it is missing. It is especially dangerous in a case of live C API, that we are not supposed to use for modifying a live model.
SUEntityGetAttributeDictionary()
Retrieves the attribute dictionary of an entity that has the given name.
If a dictionary with the given name does not exist, one is added to the entity.
If a developer is using it just to read the dictionary, as naturally expected, then it will be modifying the live model in many places, producing unnecessary dictionaries throughout a model.
There is SUEntityAddAttributeDictionary() so why adding this automatically??
Are there many things like this in C API?
I’m not sure. This function was added before my time.
Agree - bad API design. Getters should not have side effects like this.
I wonder if anyone is actually relying on the current behaviour. I don’t like breaking API behaviour, but in this case I’m leaning to consider it a bug and removing behaviour.
It would have been better if the creator function created a dictionary if it did not exist, otherwise just returned it if it did, … rather than have a getter default to creation. (Ie, the getter often doubles as a query to see if a collection has a certain member.)