WebDialog Closes Mysteriously
-
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.
http://video.google.com/videoplay?docid=1449501159821628686&hl=en
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>
-
I had to clear out my Plugins folder, but the problem went away.
I'll post if I find anything.
-
I had this problem until I made my web dialog objects global.
-
@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.
-
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?
-
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
-
@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.
-
Jim: I can take a look, if you want, and see if it shows the same behaviour here
-
@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.
-
@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
-
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.
Advertisement