Dc error when DefinitionsObserver added

I keep getting this eror when I add DefinitionsObserver. Eror appears on a unode / redo event.

Error: #<TypeError: reference to deleted Entity>
c:/users/marko/appdata/roaming/sketchup/sketchup 2018/sketchup/plugins/su_dynamiccomponents/ruby/dcobservers.rbe:908:in get_attribute' c:/users/marko/appdata/roaming/sketchup/sketchup 2018/sketchup/plugins/su_dynamiccomponents/ruby/dcobservers.rbe:908:in onActivePathChanged’

Do I do something wrong or is it a bug? Here’s a simple script after which I get that error:

class MyDefinitionsObserver < Sketchup::DefinitionsObserver
  def onComponentAdded(definitions, definition)
    puts "onComponentAdded: #{definition.name}"
  end
end
@test = MyDefinitionsObserver.new
Sketchup.active_model.definitions.add_observer(@test)

EDIT:
Now I have noticed that the error also appears without a observer, when all entities in the component or group are deleted.
So it’s not up to me! :slight_smile:
Thanks anyway!

(Better post error messages in a code block, they contain characters that Markdown might consider as markup.)

When using undo+redo, a new instance of that entity is created (add component, undo = remove it, redo = add again a component). If the reference still exists on the Ruby side but the corresponding entity on the SketchUp side does not exist anymore, inspect gives #<Deleted Entity> and all methods called on it will raise an error.

In the console log, you see that the error is caused in the file dcobservers.rbe which is not part of your code. So it is more likely a bug in that extension, not in your code. As you see, when programming with observers one needs to thoroughly plan their behavior in all edge cases, because unlike explicitely called methods (via button/menu), registered observers can always be triggered when the model changes (that can be very often) and they can conflict with other extensions.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.