Closed joonty closed 11 years ago
@joonty Thanks for the good suggestion! It's okay to add an optional status parameter and return status code. But one thing I'd like to use Kernel.exit!
instead of Kernel.exit
. Because if Kernel.exit is called in the Object#exit method, ruby displays a few error messages (at least on Windows).
So, if you allow using Kernel.exit!
instead of Kernel.exit
, please send a pull request. ;-)
OK great, thanks!
It seems that it was more complicated than expected. Those errors that you were seeing were due to GLib2's exception handler, exit_application
, that catches all exceptions and spits out a back trace. This also includes SystemExit
, so when Kernel#exit
was called, a big backtrace was printed out.
Kernel#exit!
works, as you pointed out, because it immediately stops execution. However, any user registered exception handlers or exit callbacks wouldn't run, which scuppers my situation.
I found that the best way of doing this was to patch the Glib2 exit_application
method so that it re-raises SystemExit
exceptions specifically, and then everything works as expected. I also moved the Object#exit
method in shoes out into an exit callback, as I mentioned earlier, as this will always be run when ruby shuts down (e.g. if someone raises SystemExit
instead of calling exit()
directly).
All of that just amounts to a few lines of code in the end :-P
I'll raise a pull request, but take a look through it to make sure I haven't messed anything up!
Hi, I noticed that you bumped the version number. Are you planning to push the update to rubygems.org? I'm about to release a gem, breaktime, which depends on green shoes, but at the moment I'm having to specify the git repo rather than ruby gems.
Thanks again
@joonty
Are you planning to push the update to rubygems.org?
Yes, I want. But I realized the following. I'm not sure this is a platform dependet (Windows only) issue...
# test1.rb
require 'green_shoes'
Shoes.app{}
When I do ruby test1.rb
on the console window, it works well and I can close the window by default close button with no error.
But when I do gshoes test1.rb
and close the window, I get the following segmentation fault. :(
C:\tmp>gshoes test1.rb C:/ruby/bin/gshoes: [BUG] Segmentation fault ruby 1.9.3p194 (2012-04-20) [i386-mingw32] -- Control frame information ----------------------------------------------- c:0001 p:0000 s:0002 b:0002 l:00060c d:00060c TOP -- C level backtrace information ------------------------------------------- C:\Windows\SYSTEM32\ntdll.dll(KiFastSystemCallRet+0x0) [0x77d87094] C:\Windows\system32\kernel32.dll(WaitForSingleObjectEx+0x43) [0x77a4c313] C:\Windows\system32\kernel32.dll(WaitForSingleObject+0x12) [0x77a4c2c2] C:\ruby\bin\msvcrt-ruby191.dll(rb_vm_bugreport+0xf9) [0x62e5c589] C:\ruby\bin\msvcrt-ruby191.dll(rb_name_err_mesg_new+0x17a) [0x62d3a7e2] C:\ruby\bin\msvcrt-ruby191.dll(rb_bug+0x2f) [0x62d3b4fb] C:\ruby\bin\msvcrt-ruby191.dll(rb_check_safe_str+0x1a4) [0x62dee168] [0x004011e6] C:\Windows\system32\kernel32.dll(UnhandledExceptionFilter+0xf5) [0x77a60746] C:\Windows\SYSTEM32\ntdll.dll(EtwReplyNotification+0x366) [0x77db7f02] -- Other runtime information ----------------------------------------------- * Loaded script: C:/ruby/bin/gshoes * Loaded features: 0 enumerator.so 1 C:/ruby/lib/ruby/1.9.1/i386-mingw32/enc/encdb.so 2 C:/ruby/lib/ruby/1.9.1/i386-mingw32/enc/shift_jis.so 3 C:/ruby/lib/ruby/1.9.1/i386-mingw32/enc/trans/transdb.so 4 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/defaults.rb 5 C:/ruby/lib/ruby/1.9.1/i386-mingw32/rbconfig.rb 6 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/deprecate.rb 7 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/exceptions.rb 8 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operating_system.rb 9 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb 10 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems.rb 11 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/version.rb 12 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb 13 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb 14 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb 15 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb 16 C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/path_support.rb 17 C:/ruby/lib/ruby/1.9.1/i386-mingw32/enc/utf_16le.so 18 C:/ruby/lib/ruby/1.9.1/i386-mingw32/enc/trans/utf_16_32.so 19 C:/ruby/lib/ruby/1.9.1/i386-mingw32/enc/trans/japanese_sjis.so 20 C:/ruby/lib/ruby/1.9.1/i386-mingw32/etc.so 21 C:/ruby/lib/ruby/1.9.1/fileutils.rb 22 C:/ruby/lib/ruby/1.9.1/tmpdir.rb 23 C:/ruby/lib/ruby/1.9.1/i386-mingw32/pathname.so 24 C:/ruby/lib/ruby/1.9.1/pathname.rb 25 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/color.rb 26 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/paper.rb 27 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/1.9/cairo.so 28 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/constants.rb 29 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/point.rb 30 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/colors.rb 31 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/papers.rb 32 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/context/rectangle.rb 33 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/context/triangle.rb 34 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/context/circle.rb 35 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/context/path.rb 36 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/context/blur.rb 37 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/context/color.rb 38 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/context.rb 39 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/device.rb 40 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/surface.rb 41 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/pattern.rb 42 C:/ruby/lib/ruby/1.9.1/forwardable.rb 43 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo/path.rb 44 C:/ruby/lib/ruby/gems/1.9.1/gems/cairo-1.12.2-x86-mingw32/lib/cairo.rb 45 C:/ruby/lib/ruby/1.9.1/English.rb 46 C:/ruby/lib/ruby/1.9.1/thread.rb 47 C:/ruby/lib/ruby/gems/1.9.1/gems/glib2-1.2.1-x86-mingw32/lib/glib2/deprecatable.rb 48 C:/ruby/lib/ruby/gems/1.9.1/gems/glib2-1.2.1-x86-mingw32/lib/1.9/glib2.so 49 C:/ruby/lib/ruby/gems/1.9.1/gems/glib2-1.2.1-x86-mingw32/lib/glib2.rb 50 C:/ruby/lib/ruby/gems/1.9.1/gems/pango-1.2.1-x86-mingw32/lib/1.9/pango.so 51 C:/ruby/lib/ruby/gems/1.9.1/gems/pango-1.2.1-x86-mingw32/lib/pango.rb 52 C:/ruby/lib/ruby/gems/1.9.1/gems/gdk_pixbuf2-1.2.1-x86-mingw32/lib/1.9/gdk_pixbuf2.so 53 C:/ruby/lib/ruby/gems/1.9.1/gems/gdk_pixbuf2-1.2.1-x86-mingw32/lib/gdk_pixbuf2.rb 54 C:/ruby/lib/ruby/gems/1.9.1/gems/atk-1.2.1-x86-mingw32/lib/1.9/atk.so 55 C:/ruby/lib/ruby/gems/1.9.1/gems/atk-1.2.1-x86-mingw32/lib/atk.rb 56 C:/ruby/lib/ruby/gems/1.9.1/gems/gtk2-1.2.1-x86-mingw32/lib/1.9/gtk2.so 57 C:/ruby/lib/ruby/gems/1.9.1/gems/gtk2-1.2.1-x86-mingw32/lib/gtk2/base.rb 58 C:/ruby/lib/ruby/gems/1.9.1/gems/gtk2-1.2.1-x86-mingw32/lib/gtk2.rb 59 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/ruby.rb 60 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/helper_methods.rb 61 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/colors.rb 62 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/basic.rb 63 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/main.rb 64 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/app.rb 65 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/anim.rb 66 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/slot.rb 67 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/text.rb 68 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/mask.rb 69 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/widget.rb 70 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/url.rb 71 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/style.rb 72 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/projector.rb 73 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/download.rb 74 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/manual.rb 75 C:/ruby/lib/ruby/1.9.1/find.rb 76 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/minitar.rb 77 C:/ruby/lib/ruby/1.9.1/i386-mingw32/digest.so 78 C:/ruby/lib/ruby/1.9.1/digest.rb 79 C:/ruby/lib/ruby/1.9.1/i386-mingw32/digest/md5.so 80 C:/ruby/lib/ruby/1.9.1/i386-mingw32/zlib.so 81 C:/ruby/lib/ruby/1.9.1/psych/syntax_error.rb 82 C:/ruby/lib/ruby/1.9.1/i386-mingw32/psych.so 83 C:/ruby/lib/ruby/1.9.1/i386-mingw32/stringio.so 84 C:/ruby/lib/ruby/1.9.1/psych/nodes/node.rb 85 C:/ruby/lib/ruby/1.9.1/psych/nodes/stream.rb 86 C:/ruby/lib/ruby/1.9.1/psych/nodes/document.rb 87 C:/ruby/lib/ruby/1.9.1/psych/nodes/sequence.rb 88 C:/ruby/lib/ruby/1.9.1/psych/nodes/scalar.rb 89 C:/ruby/lib/ruby/1.9.1/psych/nodes/mapping.rb 90 C:/ruby/lib/ruby/1.9.1/psych/nodes/alias.rb 91 C:/ruby/lib/ruby/1.9.1/psych/nodes.rb 92 C:/ruby/lib/ruby/1.9.1/psych/streaming.rb 93 C:/ruby/lib/ruby/1.9.1/psych/visitors/visitor.rb 94 C:/ruby/lib/ruby/1.9.1/i386-mingw32/strscan.so 95 C:/ruby/lib/ruby/1.9.1/psych/scalar_scanner.rb 96 C:/ruby/lib/ruby/1.9.1/psych/visitors/to_ruby.rb 97 C:/ruby/lib/ruby/1.9.1/psych/visitors/emitter.rb 98 C:/ruby/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb 99 C:/ruby/lib/ruby/1.9.1/psych/json/ruby_events.rb 100 C:/ruby/lib/ruby/1.9.1/psych/visitors/json_tree.rb 101 C:/ruby/lib/ruby/1.9.1/psych/visitors/depth_first.rb 102 C:/ruby/lib/ruby/1.9.1/psych/visitors.rb 103 C:/ruby/lib/ruby/1.9.1/psych/handler.rb 104 C:/ruby/lib/ruby/1.9.1/psych/tree_builder.rb 105 C:/ruby/lib/ruby/1.9.1/psych/parser.rb 106 C:/ruby/lib/ruby/1.9.1/psych/omap.rb 107 C:/ruby/lib/ruby/1.9.1/psych/set.rb 108 C:/ruby/lib/ruby/1.9.1/psych/coder.rb 109 C:/ruby/lib/ruby/1.9.1/psych/core_ext.rb 110 C:/ruby/lib/ruby/1.9.1/i386-mingw32/date_core.so 111 C:/ruby/lib/ruby/1.9.1/date/format.rb 112 C:/ruby/lib/ruby/1.9.1/date.rb 113 C:/ruby/lib/ruby/1.9.1/psych/deprecated.rb 114 C:/ruby/lib/ruby/1.9.1/psych/stream.rb 115 C:/ruby/lib/ruby/1.9.1/psych/json/yaml_events.rb 116 C:/ruby/lib/ruby/1.9.1/psych/json/tree_builder.rb 117 C:/ruby/lib/ruby/1.9.1/psych/json/stream.rb 118 C:/ruby/lib/ruby/1.9.1/psych/handlers/document_stream.rb 119 C:/ruby/lib/ruby/1.9.1/psych.rb 120 C:/ruby/lib/ruby/1.9.1/yaml.rb 121 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/shoes/shy.rb 122 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/plugins/systray.rb 123 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/plugins/thread.rb 124 C:/ruby/lib/ruby/1.9.1/i386-mingw32/socket.so 125 C:/ruby/lib/ruby/1.9.1/socket.rb 126 C:/ruby/lib/ruby/1.9.1/timeout.rb 127 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/plugins/httpd.rb 128 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/plugins/treeview.rb 129 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/plugins/code_box.rb 130 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/plugins/video.rb 131 C:/ruby/lib/ruby/gems/1.9.1/gems/green_shoes-1.1.373/lib/green_shoes.rb [NOTE] You may have encountered a bug in the Ruby interpreter or extension libraries. Bug reports are welcome. For details: http://www.ruby-lang.org/bugreport.html This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
Umm,... need to find a solution...
@joonty I realized that the above error occurs every time. So, I'm going to upload green_shoes-1.1.373.gem to RubyGems.org anyway. ;-)
Awesome! Thanks for that :)
I've now pushed my gem, breaktime - it's a screen break scheduler tool. It doesn't use shoes heavily yet, only a dialog box, but I've got plans to use it to create a GUI configuration.
Thanks, I think this is closed now.
Mine is just the opposite. ruby test.rb does give the fault but gshoes test.rb doesn't. A few times I was running a program with this line at the bottom: Shoes.instance_eval("class << self;self;end") and no fault occurred as long as you don't have anything else in the app block except regular Ruby like puts and such.
What do you mean "running a program with this line at the bottom"?
# test.rb
require 'green_shoes'
Shoes.app{}
Shoes.instance_eval("class << self;self;end")
Do you mean that running the above code without the fault?
It doesn't matter. As long as you don't put any shoes code in the block. ex para It works in scite and cmd with no fault error message.
Strange isn't it. I don't even know why I tried that because I know very little meta-programming. Not even sure what that does but I was playing around with it to get a methods list like so: p Shoes.instance_eval("class << self;self;end").methods.sort But actually it's the fact that I don't use any shoes methods in the block is what makes the fault go away. You can use puts and p anywhere you want but as soon as you use some shoes code, fault.
@DouglasAllen Thanks for the detailed information.
As long as you don't put any shoes code in the block.
I see. But on my Windows, the fault still occured... :( I realized that
But I'm not sure the above is in my case only... Anyway I reopen this issue and continue finding a solution.
I can confirm that this doesn't happen on Linux, with ruby 1.9.3 and green shoes 1.1.373. Has the seg fault found to related to the code pushed relating to this issue?
I guess that this seg fault problem is depend on platform (i.e. Windows), not related to the code (i.e. Shoes App).
I have not tried it but is there any difference in how the gem is installed? I installed this one from the github clone. I haven't really looked into all the code but is it compiled somewhere? All the dependent gems that I got were mingw32 for gtk2 and such. That is what they do with Ruby for Windows these days.
On Wed, Feb 20, 2013 at 5:51 AM, ashbb notifications@github.com wrote:
I guess that this seg fault problem is depend on platform (i.e. Windows), not related to the code (i.e. Shoes App).
— Reply to this email directly or view it on GitHubhttps://github.com/ashbb/green_shoes/issues/72#issuecomment-13828077.
I just installed green_shoes to teach my son (thanks for making it!) and get a segfault when I run a trivial program and immediately close the window. I'm on Linux (1.9.3-p327, Debian, rbenv, green_shoes 1.1.373).
Interesting. What's a trivial program? Something like Shoes.app {}
? You have a very similar setup to me, but I don't get the segfault.
@JamesLavin Thanks for trying Green Shoes!
Could you try to install the previous version? gem install green_shoes -v 1.1.367
Hope that works and have fun with your son. :)
I have the same problem on osx for both green_shoes-1.1.373 and 367.
Empty Shoe works, add a par, and it fails with the above trace. (ruby-1.9.3-p194)
Hi all, Try out green_shoes-1.1.374 and if you confirm that this issue is still there, please reopen & comment.
I've run into a clash when using this gem and main, but I can see how the problem would occur in other ways.
The exit method that is defined on the Object class in green shoes does not accept a status code parameter, which
Kernel#exit
does accept. This means that you can only call,exit
, notexit(1)
or any other variant.You could call
Kernel.exit(1)
directly, but gems like main or other calling code wouldn't know to do that.A quick fix would be to allow an optional status parameter and then call the Kernel exit:
Or perhaps a better option would be to add an
at_exit()
block, and don't cause an effective override by specifyingObject#exit()
:Any thoughts on this? I'd be happy to fork and do a pull request if you like.