sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Remove_observer bug?

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 277 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fuzzybroF Offline
      fuzzybro
      last edited by

      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?

      [OctaneRender for SketchUp Overview and Demo Version(http://sketchucation.com/click.php?url)]

      Latest updates, tutorials and artwork
      facebook.com/octane4sketchup

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        Is that code in a file that you are loading ?

        The local reference observer will be invalid after the file is done loading.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • fuzzybroF Offline
          fuzzybro
          last edited by

          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
          
          

          [OctaneRender for SketchUp Overview and Demo Version(http://sketchucation.com/click.php?url)]

          Latest updates, tutorials and artwork
          facebook.com/octane4sketchup

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement