Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webkit (Qt::WebView) crashes randomly #51

Closed
squareduck opened this issue Apr 21, 2013 · 14 comments
Closed

Webkit (Qt::WebView) crashes randomly #51

squareduck opened this issue Apr 21, 2013 · 14 comments

Comments

@squareduck
Copy link

The background

Here is what I'm using:

archlinux 64bit
gem install qtbindings

Here is my code:

require 'Qt'
require 'qtwebkit'

class QtApp < Qt::Widget
  def initialize
    super
    init_webkit
    resize(800, 600)
    show
  end

  def init_webkit
    layout = Qt::HBoxLayout.new(self)
    layout.setMargin(0)
    webkit = Qt::WebView.new(self)
    webkit.load(Qt::Url.new("http://0.0.0.0:9292"))
    layout.addWidget(webkit)
  end
end

app = Qt::Application.new ARGV
QtApp.new
app.exec

The problem

Every other time I run the app, it crashes right away. It seems like there is 50% chance that it will crash.

The crash log:

01:47:44 ~/Temp/TestApp$ ruby app.rb 
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2672: [BUG] cfp consistency error - call0
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0011 p:0328 s:0057 b:0057 l:000056 d:000056 METHOD /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2734
c:0010 p:0122 s:0038 b:0038 l:000037 d:000037 METHOD /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2677
c:0009 p:---- s:0026 b:0026 l:000025 d:000025 CFUNC  :respond_to_missing?
c:0008 p:---- s:0019 b:0019 l:000018 d:000018 FINISH
c:0007 p:---- s:0017 b:0017 l:000016 d:000016 CFUNC  :method_missing
c:0006 p:0044 s:0015 b:0015 l:000014 d:000014 METHOD app.rb:9
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :new
c:0003 p:0084 s:0007 b:0007 l:000de8 d:000a10 EVAL   app.rb:22
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000de8 d:000de8 TOP   

-- Ruby level backtrace information ----------------------------------------
app.rb:22:in `<main>'
app.rb:22:in `new'
app.rb:9:in `initialize'
app.rb:9:in `method_missing'
app.rb:9:in `respond_to_missing?'
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2677:in `do_method_missing'
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2758:in `do_method_missing'
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2758:in `each'
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2761:in `block in do_method_missing'
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2761:in `isConstMethod'

-- C level backtrace information -------------------------------------------
app.rb:9: [BUG] Segmentation fault
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0009 p:---- s:0027 b:0026 l:000025 d:000025 CFUNC  :respond_to_missing?
c:0008 p:---- s:0019 b:0019 l:000018 d:000018 FINISH
c:0007 p:---- s:0017 b:0017 l:000016 d:000016 CFUNC  :method_missing
c:0006 p:0044 s:0015 b:0015 l:000014 d:000014 METHOD app.rb:9
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :new
c:0003 p:0084 s:0007 b:0007 l:000de8 d:000a10 EVAL   app.rb:22
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000de8 d:000de8 TOP   

-- Ruby level backtrace information ----------------------------------------
app.rb:22:in `<main>'
app.rb:22:in `new'
app.rb:9:in `initialize'
app.rb:9:in `method_missing'
app.rb:9:in `respond_to_missing?'

-- C level backtrace information -------------------------------------------
/home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/libruby.so.1.9(+0x19db03) [0x7fb198c2fb03] vm_dump.c:796
/home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/libruby.so.1.9(+0x63d10) [0x7fb198af5d10] error.c:258
/home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/libruby.so.1.9(rb_bug+0xb3) [0x7fb198af6a83] error.c:277
/home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/libruby.so.1.9(+0x191861) [0x7fb198c23861] signal.c:609
/home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/libruby.so.1.9(rb_funcall+0xb1) [0x7fb198c23fb1]
/home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/libruby.so.1.9(rb_obj_respond_to+0x75) [0x7fb198c24fc5] vm.inc:1582
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/ext/build/ruby/qtruby/src/libqtruby4shared.so.2(_ZN6QtRuby7Binding10callMethodEsPvPN5Smoke9StackItemEb+0x33b) [0x7fb1937d0bb9] array.c:2485
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/ext/build/smoke/qtgui/libsmokeqtgui.so.3(_ZN12__smokeqtgui14x_QApplication6notifyEP7QObjectP6QEvent+0x53) [0x7fb195097c49]
/usr/lib/libQtCore.so.4(_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+0x8e) [0x7fb1970eb6ae]
/usr/lib/libQtCore.so.4(+0x1a6368) [0x7fb197119368]
/usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x135) [0x7fb1921e1845] bignum.c:1497
/usr/lib/libglib-2.0.so.0(+0x47b78) [0x7fb1921e1b78] bignum.c:3764
/usr/lib/libglib-2.0.so.0(g_main_context_iteration+0x34) [0x7fb1921e1c34] bignum.c:3771
/usr/lib/libQtCore.so.4(_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0x66) [0x7fb197119b66]
/usr/lib/libQtCore.so.4(_ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE+0x2f) [0x7fb1970ea3ff]
/usr/lib/libQtCore.so.4(_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE+0x138) [0x7fb1970ea688]
/usr/lib/libQtCore.so.4(_ZN7QThread4execEv+0xf0) [0x7fb196feb8a0]
/usr/lib/libQtCore.so.4(+0x7b87c) [0x7fb196fee87c]
/usr/lib/libpthread.so.0(+0x7dd2) [0x7fb19887ddd2]
/usr/lib/libc.so.6(clone+0x6d) [0x7fb197c6dced]

-- Other runtime information -----------------------------------------------

* Loaded script: app.rb

* Loaded features:

    0 enumerator.so
    1 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so
    2 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so
    3 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/defaults.rb
    4 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/x86_64-linux/rbconfig.rb
    5 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/deprecate.rb
    6 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/exceptions.rb
    7 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
    8 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems.rb
    9 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/version.rb
   10 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb
   11 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb
   12 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb
   13 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/path_support.rb
   14 /home/squareduck/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb
   15 /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb
   16 /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/1.9/qtruby4.so
   17 /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt4.rb
   18 /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt.rb
   19 /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/qtwebkit/qtwebkit.rb
   20 /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/1.9/qtwebkit.so

Also, rarely it is not segfaulting, but exiting with this error:

01:47:45 ~/Temp/TestApp$ ruby app.rb 
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2730: [BUG] cfp consistency error - call0
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0001 p:0000 s:0002 b:0002 l:000048 d:000048 TOP   


-- C level backtrace information -------------------------------------------
/home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2730:in `findMethod': can't convert nil into String (TypeError)
        from /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2730:in `respond_to_missing?'
        from /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2730:in `block in do_method_missing'
        from /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2730:in `collect'
        from /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2730:in `do_method_missing'
        from /home/squareduck/.rvm/gems/ruby-1.9.3-p392/gems/qtbindings-4.8.3.0/lib/Qt/qtruby4.rb:2677:in `do_method_missing'
        from app.rb:9:in `method_missing'
        from app.rb:9:in `initialize'
        from app.rb:22:in `new'
        from app.rb:22:in `<main>'

I will provide any additional info if required.

@jmthomas
Copy link
Collaborator

Seems to work reliably on Windows XP with Ruby 1.9.3p286 and qtbindings 4.8.3.0. I changed your web address to a public site and that displayed correctly as well. I've had success running on a 64 bit version of CentOS but that might have been version 4.6.3.4. Have you tried that version?

@squareduck
Copy link
Author

I've uninstalled the latest gem and installed 4.6.3.4.
Same result, I got 4 successful runs in a row, but the fifth crashed.
Crash log:
http://pastebin.com/p3xkjaGX

@jmthomas
Copy link
Collaborator

Is this specifically a crash within Webkit? Have you tried another public web address. I didn't have luck with https addresses but www.macrumors.com worked. :-) Is the program stable without the Webkit stuff. I don't have the bandwidth or the machine to try to figure out the underlying problem.

@cmpitg
Copy link

cmpitg commented Apr 23, 2013

Not sure if this helps, I got the (same kind?) of crash when using QTreeView with QFileSystemModel (see #50). I don't think it's specific to Webkit.

@supermomonga
Copy link

I'm using Mac OS X and got same problem with following simple code.

require 'Qt4'
require 'qtwebkit'

Qt::Application.new ARGV do |app|
  Qt::WebView.new do |webview|
    webview.load Qt::Url.new 'http://google.co.jp/'
    webview.show
  end
  app.exec
end
  • ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.0]
  • qtbindings (4.8.3.0)

Has someone any solutions?

@djellemah
Copy link

I get the cfp consistency crash from this:

require 'Qt'
require 'qtwebkit'

class HtmlViewer < Qt::Widget
  def initialize
    super

    resize 1024, 768
    move 300, 300

    view = Qt::WebView.new self

    layout = Qt::VBoxLayout.new(self)
    layout.add_widget view

    url = 'http://djellemah.com'
    view.load Qt::Url.new(url)
  end
end

app = Qt::Application.new ARGV
viewer = HtmlViewer.new
viewer.show
app.exec

Seems fairly random - the same page will work, and then crash 8 or so times in a row, then work again.

I have other qt-bindings apps on this box which are working fine.

  • qtbindings-4.8.3.0
  • ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]

@djellemah
Copy link

Here's the last few lines of a gdb stack trace:

#3  0xb7e14b1e in rb_bug (fmt=0xb7f8dbae "cfp consistency error - call0") at error.c:284
#4  0xb7f4fc58 in vm_call0 (th=0xb79c5d74, recv=136575620, id=2975, argc=2, argv=0xb23fe000, me=<optimized out>) at vm_eval.c:82
#5  0xb7f5095a in rb_call (scope=CALL_FCALL, argv=0xb23fe000, argc=2, mid=2975, recv=136575620) at vm_eval.c:456
#6  rb_funcall (recv=136575620, mid=2975, n=2) at vm_eval.c:658
#7  0xb7f515af in rb_obj_respond_to (obj=136575620, id=26240, priv=0) at vm_method.c:1225
#8  0xb7f5174c in rb_respond_to (obj=136575620, id=26240) at vm_method.c:1232
#9  0xb589214e in QtRuby::Binding::callMethod(short, void*, Smoke::StackItem*, bool) ()
   from /usr/local/rvm-installed/gems/ruby-1.9.3-p392@delve/gems/qtbindings-4.8.3.0/ext/build/ruby/qtruby/src/libqtruby4shared.so.2
#10 0xb61e6a6a in __smokeqtgui::x_QApplication::notify(QObject*, QEvent*) ()

@djellemah
Copy link

Same crash with ruby-2.0.0 and qtbindings-4.6.3.4

So I built qtbindings with some debug info, including some of the qWarning output in callMethod. Here's the output from running it in gdb: http://pastebin.com/NE5qB93s and here is 'thread apply all bt' http://pastebin.com/ppVV2cXi

I'm suspecting some kind of threading issue, because when I run it under valgrind it does not crash. There are a whole lot of potential threading issues identified by helgrind though. I don't know if any of them are relevant.

@djellemah
Copy link

I've recompiled ruby and qtbindings with debug symbols and no compiler optimisations. I put a breakpoint at the line in ruby that calls rb_bug with "cfp consistency error". Sure enough there are 2 threads in the ruby vm. Which is most likely the problem.

My guess is Binding::callMethod (and maybe callMethod on other c++ classes) shouldn't allow more than one thread into the ruby vm.

One solution is here: http://burgestrand.se/articles/asynchronous-callbacks-in-ruby-c-extensions.html

ffi does this to deal with it: https://github.com/ffi/ffi/wiki/Callbacks

@djellemah
Copy link

diff --git a/ext/ruby/qtruby/src/Qt.cpp b/ext/ruby/qtruby/src/Qt.cpp
index 45e6ca7..5daa5c3 100644
--- a/ext/ruby/qtruby/src/Qt.cpp
+++ b/ext/ruby/qtruby/src/Qt.cpp
@@ -287,6 +287,7 @@ Binding::callMethod(Smoke::Index method, void *ptr, Smoke::Stack args, bool /*is
                                        ptr,
                                        smoke->classes[smoke->methods[method].classId].className,
                                        (const char *) signature );
+    qWarning( "native thread? %i", ruby_native_thread_p() );
        }

        if (o == 0) {
@@ -476,18 +477,18 @@ InvokeNativeSlot::cleanup()

 }

@ryanmelt
Copy link
Owner

ryanmelt commented Dec 4, 2013

This should be resolved with qtbindings 4.8.5.1. Please comment if not.

@ryanmelt ryanmelt closed this as completed Dec 4, 2013
@marguerite
Copy link

@ryanmelt

Hi, Ryan

I ran into exactly the same issue as this thread describles, but I'm using openSUSE 13.2 w/ ruby 2.1.4 and ruby-qt4 4.14.2...in your project I didn't see any new release after 4.8.x...so I think it might be quite embarrassed if I report a bug for software I'm not using at all...

Can you please take some time and check https://bugzilla.opensuse.org/show_bug.cgi?id=905512 to see if I was barking the same issue?

Thanks

Marguerite

@ryanmelt
Copy link
Owner

Hello marguerite - ruby-qt4 is not qtbindings, is is the outdated qtruby.

You should probably uninstall that and then:
gem install qtbindings

@marguerite
Copy link

@ryanmelt

Haha! I figured it out...at first I thought it was newer than qtbindings because it's 4.14.3 > 4.8.6.0, then an idea came out in my mind: You're following the Qt version scheme...

Actually I opened a KDE bugreport here:

https://bugs.kde.org/show_bug.cgi?id=340977

because sometimes we just can't require users to install rvm for a working KDE plasmoid...I think porting your fix back to KDE qtruby is still worthy. Of course I've switched my own application (https://github.com/marguerite/BiliGui) to qtbindings :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants