• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

WebDialog Closes Mysteriously

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 4 Posters 932 Views
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.
  • J Offline
    Jim
    last edited by 19 Apr 2008, 12:54

    Can anyone think of a reason my dialog would just close on its own?

    I'm uploading a video, but all I am doing is moving the mouse around and it closes.

    Here's the video. You can see it closes immediately the first time.

    Error 404 (Not Found)!!1

    favicon

    (video.google.com)

    Here's the "offending" code.

    require "sketchup"
    
    def create_dialog
      dlg = UI;;WebDialog.new("Jitter", false, "Jitter2", 100, 100, 100, 100, true)
      dlg.set_file( File.join( File.dirname(__FILE__),  "ui.html" ))
      dlg.show {}
    end
    
    name = "jitter.rb"
    unless file_loaded? name
      UI.menu("Plugins").add_item("Jitter Vertices") { create_dialog }
      file_loaded name
    end
    
    
    <html>
      <body>
        <fieldset>
          <legend>Jitter</legend>
          <input type="text" id="jitter_amount" size="5">
          <button>Jitter</button>
        </fieldset>
      </body>
    </html>
    
    
    
    

    Hi

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 19 Apr 2008, 13:37

      I had to clear out my Plugins folder, but the problem went away.

      I'll post if I find anything.

      Hi

      1 Reply Last reply Reply Quote 0
      • W Offline
        Whaat
        last edited by 19 Apr 2008, 22:29

        I had this problem until I made my web dialog objects global.

        SketchUp Plugins for Professionals

        1 Reply Last reply Reply Quote 0
        • A Offline
          AdamB
          last edited by 20 Apr 2008, 05:36

          @whaat said:

          I had this problem until I made my web dialog objects global.

          I could totally believe thats the problem. ie Ruby (correctly) garbage collects when it goes out of scope.

          Developer of LightUp Click for website

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by 20 Apr 2008, 11:05

            Yes, but the problem goes away if I clear the Plugins folder, and load only this code.

            I don't understand how the scope is the reason. If that were so, wouldn't many other plugins go out of scope and not work?

            Hi

            1 Reply Last reply Reply Quote 0
            • T Offline
              tbd
              last edited by 20 Apr 2008, 11:15

              name clashing? search for other plugins with create_dialog, dlg.
              maybe there is a conflict somewhere.

              or you can add plugin by plugin and see the offending one

              SketchUp Ruby Consultant | Podium 1.x developer
              http://plugins.ro

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by 20 Apr 2008, 13:34

                @unknownuser said:

                name clashing? search for other plugins with create_dialog, dlg.
                maybe there is a conflict somewhere.

                or you can add plugin by plugin and see the offending one

                Thanks for the comments.

                I replaced all occurrences of "jitter" with "shake", but it still happens. I recursively grep'd through the Plugins folder for "shake", and mine is the only occurrence.

                My latest custom toolbars plugin is one that causes the problem. However, it can't be Whaat's problem because no one else has this plugin yet. My toolbars plugin reads a text file, loads a file, and creates Toolbar objects.

                Here's an example "command" file:

                
                cmd = UI;;Command.new("Arc") { Sketchup.send_action "selectArcTool;" }
                cmd.large_icon = "../images/arc_lg.png"
                cmd.small_icon = "../images/arc_sm.png"
                cmd.tooltip = "Arc"
                cmd.status_bar_text = "Draw arcs"
                cmd.menu_text = "Arc"
                cmd.set_validation_proc { tool_validation_proc("ArcTool") }
                @cmd = cmd
                
                

                and here's a simpified example of how I am loading it:

                
                ruby_files.each do |file|
                  load file
                  toolbar.add_item @cmd
                end
                
                

                See any problems here? The plugin is not ready for the public, but I can share it if anyone wants to have a look for any problems.

                Hi

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tbd
                  last edited by 20 Apr 2008, 13:47

                  Jim: I can take a look, if you want, and see if it shows the same behaviour here

                  SketchUp Ruby Consultant | Podium 1.x developer
                  http://plugins.ro

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 20 Apr 2008, 14:04

                    @unknownuser said:

                    Jim: I can take a look, if you want, and see if it shows the same behaviour here

                    I've sent the plugin in a PM, thank you.

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      AdamB
                      last edited by 20 Apr 2008, 16:29

                      @jim said:

                      Yes, but the problem goes away if I clear the Plugins folder, and load only this code.

                      I don't understand how the scope is the reason. If that were so, wouldn't many other plugins go out of scope and not work?

                      Sure, but in doing so you're changing the character of garbage collection.

                      My hunch (based on nothing) is that the schema handler stuff (ie skp:blah) just expects the dialog to stay in scope although its an asynchronous process. Your code exits the block and does other stuff, 256 opcodes later (yes, I saw it in the Ruby source code - ouch!) the GC kicks in and sweeps it away. The javascript side then gets its knickers in a twist because the Ruby side dialog that was consuming data has disappeared.

                      Adam

                      Developer of LightUp Click for website

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by 20 Apr 2008, 18:01

                        Thanks for the comments, everyone; and especially to TBD.

                        It seems obvious now, but the variable that is referencing the dialog is local to the method. When the method is finished, so is everything else in the same scope. And so sooner or later the variable will get cleaned up by Ruby's garbage collection, and the dialog "mysteriously" goes away. So for the code I posted, a global variable will solve the problem. You could also use an instance variable.

                        Please, correct any mis-understandings I have about what's happening.

                        Hi

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

                        Advertisement