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

    Unload / reload plugin without closing SketchUp

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 3 Posters 2.1k Views 3 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      I also note that you refer to using EntitiesObservers - these are well known for causing issues. https://developers.google.com/sketchup/docs/ourdoc/entitiesobserver

      @unknownuser said:

      WARNING: The methods of this observer fire in such a way that making changes to the model while inside of them is dangerous. If you experience sudden crashes, it could be because of this observer. A potential workaround is to use a ToolsObserver to watch what the user is doing instead.

      So using an alternative IS recommended/possible...

      If they are only attached during the very operation of you tool then maybe they'll be OK, but if they 'persist' into the operation of normal Sketchup then they can cause other innocent tools to crash, because they are then seen to be somehow changing the model's entities while the observer is active... I had an issue with one of my tools crashing because of a 3rd party tool made such an observer that persisted. I recoded to erase only the unwanted groups etc by using .clear! on their entities, so that the closing commit_operation cleaned up, rather than directly erasing them inside the start/commit block [which activated the crash]... Of course scripts should be allowed to do legitimate operations without fear of falling foul of someone else's ill-considered observer...
      Indeed it was found that even a completely 'empty' EntitiesObserver will cause such unexpected crashes, if it's left active during the operation of some other tool that innocently changes the entities within a start/commit block.

      TIG

      1 Reply Last reply Reply Quote 0
      • brewskyB Offline
        brewsky
        last edited by

        @tig said:

        So using an alternative IS recommended/possible...

        Hmmm, I already changed "SelectionObserver.onSelectionAdded" to "SelectionObserver.onSelectionBulkChange" because of a warning like that.

        I will try to get rid of that one too!

        But this is probably the most important to be able to disable all observers.

        And yeah, maybe it's enough to just have a disable-observer button instead of trying to unload the entire plugin. If someone really wants it completely disabled then the unload-extension feature(with restart) can always be used(and is probably the only thing that makes sure it's completely unloaded).

        Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @brewsky said:

          And yeah, maybe it's enough to just have a disable-observer button instead of trying to unload the entire plugin. If someone really wants it completely disabled then the unload-extension feature(with restart) can always be used(and is probably the only thing that makes sure it's completely unloaded).

          Yes. Keep track of your observers (and try to make them do as little as possible) and ensure you remove them all when not needed.
          When I need to use observers I try to make them as light as possible - simply keeping a cache of the info I get from the observers (unprocessed) - then at safe points I process and react on them.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Btw, have you seen this list: http://www.thomthom.net/software/sketchup/observers/ ?

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • brewskyB Offline
              brewsky
              last edited by

              @thomthom said:

              simply keeping a cache of the info I get from the observers (unprocessed) - then at safe points I process and react on them.

              You mean like, create an array of "objects that need to be updated", and process the array seperately(like once a second with a timer)?

              Thanks for the list, I will try to pick the least buggy ones πŸ˜„

              Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @brewsky said:

                You mean like, create an array of "objects that need to be updated", and process the array seperately(like once a second with a timer)?

                No - not like a timer, because that might trigger in the middle of another operation, just like observer events. But just in time before you need to.
                (Hard to give specific examples when I don't know how your plugin works.)

                Ideally we would have an observer event for when an operation completed - but alas.

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • brewskyB Offline
                  brewsky
                  last edited by

                  @thomthom said:

                  (Hard to give specific examples when I don't know how your plugin works.)

                  I am using 2 kinds of objects:

                  • source objects (faces)
                  • geometry objects, like walls (groups)
                    When a source face is moved the wall needs to be re-drawn to match shape and position.
                    Check out this video(around 1:30): http://www.youtube.com/watch?v=J59EgH7LICs

                  The plugin will probably work best when the update is fired immediately...

                  Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    @brewsky said:

                    When a source face is moved the wall needs to be re-drawn to match shape and position.

                    Problem is, if you modify the model on an entities event you might interrupt an existing process. Some other tool might be causing your observer to trigger in the middle of it's operation. That would either prevent it from completing or at worst crash SketchUp

                    I ran into lots of these problems myself a while ago when I tried to make a plugin reacting to observer events: http://sketchucation.com/forums/viewtopic.php?f=180&t=19011#p155886

                    You're running into the same type of issue as what I did, and also what Dynamic Components are doing. I talked to Scott about what he did to solve the matter. He said he used various observers to find safe points to react to. A key observer was the Tools observer, checking for the change of state with tools. They can usually be translated into operation commits and - possibly safe. I think he observed the Tools stack for when the native Move, Rotate and Scale tool completed.

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • brewskyB Offline
                      brewsky
                      last edited by

                      @thomthom said:

                      I talked to Scott about what he did to solve the matter. He said he used various observers to find safe points to react to.

                      Thanks! Won't be easy to get it entirely stable I guess...

                      The "disable observers" button is probably a good starting point.
                      But I think it will need a lot of re-structuring before I have figured that out in it's entirety.

                      Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        Yea - the key is that you're plugin is not the only one operating and observer events can trigger in the middle of other operations. That's why I talked about caching the observer data until you find a "safe point" to execute. Mapping out this is important to avoid headache. Keeping observers to a minimum is best IMO - reduces overhead and risk of conflicts. Consider each observer if you really need it.

                        I'm a bit more liberal with observers when I use them within the operation of my own custom Tools. (Within a Tool class) as I then assume I have greater control over the environment.

                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        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