Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Jan Wedekind
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-05-07 18:39
I discovered that I added a call to XInitThreads (after initialising Qt::Application) in my program which was causing all this. XVideo-display is working again. So it was all my fault.

Sorry about this.

By: Jan Wedekind
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-05-07 17:26
In the debugging session above it only crashed when *closing* the window. Without debugger it crashes when opening the window.

By: Jan Wedekind
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-05-07 17:21
The XVideo widget for QtRuby4 which I developed is crashing when opening the window (I think I have recently updated Qt4, it used to work before). I am trying to solve the problem. If anyone has an idea what's going on, let me know.

libqt4-ruby 4:4.0.3-0ubuntu4~gutsy1~ppa1
libqt4-gui 4.3.2-0ubuntu3.2

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1211537744 (LWP 19373)]
0xb7d057eb in free () from /lib/tls/i686/cmov/libc.so.6
(gdb) up
#1 0xb6404e9e in _XFreeMutex (lip=0x809ac84) at ../../src/locking.c:132
132 ../../src/locking.c: No such file or directory.
in ../../src/locking.c
(gdb)
#2 0xb641d7b9 in XrmDestroyDatabase (db=0x809ac78) at ../../src/Xrm.c:2659
2659 ../../src/Xrm.c: No such file or directory.
in ../../src/Xrm.c
(gdb)
#3 0xb6406edc in _XFreeDisplayStructure (dpy=0x82555e8)
at ../../src/OpenDis.c:826
826 ../../src/OpenDis.c: No such file or directory.
in ../../src/OpenDis.c
(gdb)
#4 0xb63f3eea in XCloseDisplay (dpy=0x82555e8) at ../../src/ClDisplay.c:82
82 ../../src/ClDisplay.c: No such file or directory.
in ../../src/ClDisplay.c
(gdb)
#5 0xb6a3daa6 in qt_cleanup () at kernel/qapplication_x11.cpp:2117
2117 kernel/qapplication_x11.cpp: No such file or directory.
in kernel/qapplication_x11.cpp
Current language: auto; currently c++
(gdb)
#6 0xb69e0b72 in ~QApplication (this=0x80ce460) at kernel/qapplication.cpp:966
966 kernel/qapplication.cpp: No such file or directory.
in kernel/qapplication.cpp
(gdb)
#7 0xb49dd7bb in ?? () from /usr/lib/kde4/lib/libsmokeqt.so.2
(gdb)
#8 0x080ce460 in ?? ()
(gdb)
#9 0x0000002b in ?? ()
(gdb)
#10 0x080ce460 in ?? ()
(gdb)
#11 0xb4e2f078 in ?? () from /usr/lib/ruby/1.8/i486-linux/qtruby4.so

By: Jan Wedekind
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-04-01 11:18
It works (under GNU/Linux)!
http://www.wedesoft.demon.co.uk/hornetseye-api/files/xvideo-txt.html
Now one can write apps like Miro in Ruby.

By: Jan Wedekind
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-03-28 11:10
I cannot set a QApplication object as a parent of a QWidget object since QWidget::setParent expects a QWidget as parameter in contrast to QObject::setParent which only expects a QObject. That's why I am declaring a QObject and changing its parent later.
Thanks to both of you for your swift reply. I will let you know when I've managed to finish the implementation.

By: Richard Dale
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-03-28 07:31
You're allocating the 'wrapper' instance on the stack, and it will be deleted when you exit wrapNew() which doesn't look right to me. I'm not sure why you are allocating both a 'wrapper' and a 'xvWidget' instance, as findChild() will work with any subclass of Qt::Object

By: Richard Dale
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-03-28 07:28
"Maybe libsmoke must only destroy objects it has allocated itself?"

Yes, that is exactly what is happening. If an object has been instantiated on the C++ side, then the QtRuby runtime assumes it will be deleted on the C++ side too.

By: Jan Wedekind
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-03-28 02:28
I have tried this already. When I add a finalizer in Ruby it does get invoked:

ObjectSpace.define_finalizer(xv) { |id| puts "XvWidget being destroyed" }

Maybe libsmoke must only destroy objects it has allocated itself? I think I will register the object with the garbage collector myself and see whether this works.

By: Vincent Fourmond
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-03-27 17:22
Just a small clarification: GC::start will not force Ruby to GC your object, it is just a hint that you think it's the right time to cleanup.

If that is not too delicate, you can also try a loop where you create an instance of your object that should be GCed at every iteration. Your destructor should be called eventually.

By: Vincent Fourmond
RE: QtRuby4 and destruction of custom widgets [ reply ]  
2008-03-27 17:20
Hello,

I'm unsure, but that might simply mean that your object is never garbage-collected, which can perfectly be the case. Try an explicit GC::start, or try connecting the destroyed() signal to see if anything changes.

Cheers,

Vincent

By: Jan Wedekind
QtRuby4 and destruction of custom widgets [ reply ]  
2008-03-27 15:58
Hi Richard,
I am trying to integrate a custom widget for XVideo acceleration in QtRuby4. The motivation is to be able to have fast video display in a QtRuby application. It is working already but the C++ destructor of the XvWidget does not get called even though it is virtual. Do you have any idea why this is the case?
Thanks in advance.

VALUE XvWidget::wrapNew( VALUE rbClass )
{
VALUE retVal = Qnil;
XvWidget *xvWidget = NULL;
try {
// See Richard Dale's blog-entry on how to fish for Qt objects:
// http://www.kdedevelopers.org/node/2679
QObject wrapper( QCoreApplication::instance() );
wrapper.setObjectName( "HORNETSEYE-XVWIDGETWRAPPER" );
VALUE rbWrapper =
rb_eval_string( "Qt::CoreApplication.instance.findChild"
"( Qt::Object, 'HORNETSEYE-XVWIDGETWRAPPER' )" );
xvWidget = new XvWidget;
xvWidget->setObjectName( "XvWidget" );
wrapper.setParent( xvWidget );
retVal = rb_funcall( rbWrapper, rb_intern( "parent" ), 0 );
} catch ( exception &e ) {
if ( xvWidget != NULL ) delete xvWidget;
rb_raise ( rb_eRuntimeError, e.what() );
};
return retVal;
}