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 end
and 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
observer
will 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