Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download
Remove_observer bug?
-
Hi,
I have found following strange behaviour:
I have one EntitiesObserver object and multiple definitions which are bound to the very same EntitiesObserver:
observer = MyEntitiesObserver.new Sketchup;;active_model.definitions.each do |definition| definition.entities.add_observer observer endand it works OK.
But when I try to remove observer from the entities I'm able to remove it only from the first definition in the list. Other definition.entities.remove_observer(observer) are giving me the 'false' result and entities are still being observed by this observer.
How do I properly unobserve multiple objects pointing to a single observer?
-
Is that code in a file that you are loading ?
The local reference
observerwill be invalid after the file is done loading. -
It's a pseudo-code. The actual code implies that observer object is a class instance variable:
class Scene attr_accessor(;observer) def initialize @observer = MyEntitiesObserver.new end def observe Sketchup;;active_model.definitions.each do |definition| definition.entities.add_observer @observer end end def unobservre Sketchup;;active_model.definitions.each do |definition| definition.entities.remove_observer @observer end end end
Advertisement