SFML & Qt not working well together.



  • Hello,

    long story short I have an sf::RenderWindow instance (public static variable of class GS) and depending on when I create it with sf::RenderWindow::create I get nothing or a segmentation fault.

    If my code is as follows:

    // ...
    QApplication app(argc, argv);
    // ...
    std::cout << "foo" << std::endl;
    GS::window.create(sf::VideoMode(GS::resWidth, GS::resHeight), "Some Window :D");
    std::cout << "foo" << std::endl;
    // ...
    

    then I only get one foo and the program is stalled indefinitely at that point.

    If my code is as follows:

    // ...
    GS::window.create(sf::VideoMode(GS::resWidth, GS::resHeight), "Some Window :D");
    // ...
    QApplication app(argc, argv);
    // ...
    

    then the window is created successfully (although there's nothing on it yet) and the program goes on. As the program progresses, valgrind spots a few problems:

    (Menu.cpp:27 is QApplication app(argc, argv); and Menu.cpp:36 is return app.exec();)

    ==5347== Conditional jump or move depends on uninitialised value(s)
    ==5347==    at 0x1B8C14BA: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x98425E6: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x985B087: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x985C211: g_signal_emit_by_name (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x9849B38: g_object_set_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x984A396: g_object_set (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x5FAAEE5: QGtkStylePrivate::initGtkWidgets() const (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5F2E07C: QStyleFactory::create(QString const&) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5ECD98B: QApplication::style() (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5ECDCE4: QApplicationPrivate::initialize() (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5ECDD32: QApplicationPrivate::construct() (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5832B5: main (Menu.cpp:27)
    ==5347== 
    ==5347== Conditional jump or move depends on uninitialised value(s)
    ==5347==    at 0x9AF9320: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x1B8C46A0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4C2D: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4F1E: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x98423B7: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x9853556: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x985BA28: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x985BCE1: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x1BA4863F: gtk_widget_realize (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1BA49917: gtk_widget_set_parent (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8F25B2: gtk_fixed_put (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x9845486: g_cclosure_marshal_VOID__OBJECTv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347== 
    ==5347== Conditional jump or move depends on uninitialised value(s)
    ==5347==    at 0x9AF934F: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x1B8C46A0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4C2D: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4F1E: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x98423B7: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x9853556: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x985BA28: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x985BCE1: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347==    by 0x1BA4863F: gtk_widget_realize (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1BA49917: gtk_widget_set_parent (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8F25B2: gtk_fixed_put (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x9845486: g_cclosure_marshal_VOID__OBJECTv (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4002.0)
    ==5347== 
    ==5347== Conditional jump or move depends on uninitialised value(s)
    ==5347==    at 0x9AF9320: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x1B8C46A0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4C2D: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4D0F: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1BE5ECE6: ??? (in /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x9ACBCE4: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC047: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC0EB: g_main_context_iteration (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x6EBB98B: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E6D96A: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E740E0: QCoreApplication::exec() (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x5833FB: main (Menu.cpp:36)
    ==5347== 
    ==5347== Conditional jump or move depends on uninitialised value(s)
    ==5347==    at 0x9AF934F: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x1B8C46A0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4C2D: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4D0F: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1BE5ECE6: ??? (in /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x9ACBCE4: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC047: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC0EB: g_main_context_iteration (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x6EBB98B: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E6D96A: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E740E0: QCoreApplication::exec() (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x5833FB: main (Menu.cpp:36)
    ==5347== 
    ==5347== Conditional jump or move depends on uninitialised value(s)
    ==5347==    at 0x9AF9320: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x1B8C46A0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4D28: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1BE5ECE6: ??? (in /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x9ACBCE4: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC047: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC0EB: g_main_context_iteration (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x6EBB98B: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E6D96A: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E740E0: QCoreApplication::exec() (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x5833FB: main (Menu.cpp:36)
    ==5347== 
    ==5347== Conditional jump or move depends on uninitialised value(s)
    ==5347==    at 0x9AF934F: g_utf8_offset_to_pointer (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x1B8C46A0: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1B8C4D28: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x1BE5ECE6: ??? (in /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0.2400.23)
    ==5347==    by 0x9ACBCE4: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC047: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x9ACC0EB: g_main_context_iteration (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
    ==5347==    by 0x6EBB98B: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E6D96A: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6E740E0: QCoreApplication::exec() (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x5833FB: main (Menu.cpp:36)
    ==5347== 
    

    Then, the program ultimately encounters a segfault when using sf::RenderWindow::draw on an sf::Text instance. Here is what valgrind has to say about it:

    ==5347== Invalid read of size 8
    ==5347==    at 0x5055BA8: sf::Font::getTexture(unsigned int) const (in /usr/local/lib/libsfml-graphics.so.2.3.0)
    ==5347==    by 0x5081AF2: sf::Text::draw(sf::RenderTarget&, sf::RenderStates) const (in /usr/local/lib/libsfml-graphics.so.2.3.0)
    ==5347==    by 0x5076D38: sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) (in /usr/local/lib/libsfml-graphics.so.2.3.0)
    ==5347==    by 0x52E909: BlitOtherStuff() (Functions.cpp:1577)
    ==5347==    by 0x52EC32: Loop() (Functions.cpp:1615)
    ==5347==    by 0x5126E6: GS::Run() (GS.cpp:2272)
    ==5347==    by 0x4E8ABC: OpeningInterface::GoSolitaire() (OpeningInterface.cpp:46)
    ==5347==    by 0x586100: OpeningInterface::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_OpeningInterface.cpp:74)
    ==5347==    by 0x6E962A5: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6238E41: QAbstractButton::clicked(bool) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5FC2095: QAbstractButtonPrivate::emitClicked() (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5FC2BAD: QAbstractButtonPrivate::click() (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==  Address 0xffeffc4e8 is not stack'd, malloc'd or (recently) free'd
    ==5347== 
    ==5347== Invalid read of size 4
    ==5347==    at 0x5055BC4: sf::Font::getTexture(unsigned int) const (in /usr/local/lib/libsfml-graphics.so.2.3.0)
    ==5347==    by 0x5081AF2: sf::Text::draw(sf::RenderTarget&, sf::RenderStates) const (in /usr/local/lib/libsfml-graphics.so.2.3.0)
    ==5347==    by 0x5076D38: sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&) (in /usr/local/lib/libsfml-graphics.so.2.3.0)
    ==5347==    by 0x52E909: BlitOtherStuff() (Functions.cpp:1577)
    ==5347==    by 0x52EC32: Loop() (Functions.cpp:1615)
    ==5347==    by 0x5126E6: GS::Run() (GS.cpp:2272)
    ==5347==    by 0x4E8ABC: OpeningInterface::GoSolitaire() (OpeningInterface.cpp:46)
    ==5347==    by 0x586100: OpeningInterface::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (moc_OpeningInterface.cpp:74)
    ==5347==    by 0x6E962A5: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
    ==5347==    by 0x6238E41: QAbstractButton::clicked(bool) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5FC2095: QAbstractButtonPrivate::emitClicked() (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==    by 0x5FC2BAD: QAbstractButtonPrivate::click() (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
    ==5347==  Address 0x8b287f8b48000020 is not stack'd, malloc'd or (recently) free'd
    ==5347== 
    

    However, my SFML project works fine if I launch it entirely before QApplication app(argc, argv); or if I launch it in a separate program where I'm not using Qt at all. If somebody has any idea why SFML and Qt seem to conflict with each other, please share.

    Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.