hugoam / kiui

Auto-layout Ui library, lightweight, skinnable and system agnostic, with an OpenGL backend
zlib License
749 stars 71 forks source link

Crash on kiui_example startup #22

Closed alexeyknyshev closed 9 years ago

alexeyknyshev commented 9 years ago

gdb bt:

0 mk::Dockbar::vappend mkDockbar.cpp 56 0x7ffff7a2aa5d
1 mk::Sheet::emplace<mk::StyleEdit, mk::Styler&> mkSheet.h 54 0x7ffff7ac54fa
2 mk::createUiStyleEdit mkUiExample.cpp 478 0x7ffff7abb70a
3 mk::createUiTest mkUiExample.cpp 551 0x7ffff7abbea8
4 main example.cpp 36 0x41e192

in Dockbar::vappend(unique_ptr widget) widget param is null

Maybe something wrong with make_unique from mkMake.h (case STD_NO_MAKE_UNIQUE)

Crashes commit: 7435e093 Not buildable: b3c658eb17 ------------------| 2521e35e42 ------------------| ceb8b338d Last ok commit: 5c92d9254

Regards, Alexey Knyshev

hugoam commented 9 years ago

Cannot reproduce. My best guess is that one of the data files hasn't been updated in your data install folder (from the last commits)

mrzv commented 9 years ago

I have the same problem with the latest master. I'm getting a segfault with the following backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7a082cb in mk::Dockbar::vappend (this=0x91c740, widget=std::unique_ptr<mk::Widget> containing 0x0) at /home/users/morozov/Projects/U
pstream/kiui/src/Ui/Scheme/mkDockbar.cpp:57
(gdb) back
#0  0x00007ffff7a082cb in mk::Dockbar::vappend (this=0x91c740, widget=std::unique_ptr<mk::Widget> containing 0x0) at /home/users/morozov/Projec
ts/Upstream/kiui/src/Ui/Scheme/mkDockbar.cpp:57
#1  0x00007ffff7ab8f6e in mk::Sheet::emplace<mk::StyleEdit, mk::Styler&> (this=0x91c740) at /home/users/morozov/Projects/Upstream/kiui/src/Ui/W
idget/mkSheet.h:54
#2  0x00007ffff7aac6f0 in mk::createUiStyleEdit (parent=...) at /home/users/morozov/Projects/Upstream/kiui/src/Ui/mkUiExample.cpp:520
#3  0x00007ffff7aace8e in mk::createUiTest (root=...) at /home/users/morozov/Projects/Upstream/kiui/src/Ui/mkUiExample.cpp:593
#4  0x000000000041e5d2 in main (argc=1, argv=0x7fffffffe488) at /home/users/morozov/Projects/Upstream/kiui/example/example.cpp:36
(gdb) up
#1  0x00007ffff7ab8f6e in mk::Sheet::emplace<mk::StyleEdit, mk::Styler&> (this=0x91c740) at /home/users/morozov/Projects/Upstream/kiui/src/Ui/W
idget/mkSheet.h:54
(gdb) down
#0  0x00007ffff7a082cb in mk::Dockbar::vappend (this=0x91c740, widget=std::unique_ptr<mk::Widget> containing 0x0) at /home/users/morozov/Projec
ts/Upstream/kiui/src/Ui/Scheme/mkDockbar.cpp:57
alexeyknyshev commented 9 years ago

Exactly same bt on very fresh installation of debian 9 Vote up. It's a blocker on Linux.

hugoam commented 9 years ago

I'll investigate, but if someone on the system where it fails, can step the debugger to find a plausible origin, it's welcome.

mrzv commented 9 years ago

The problem turns out to be very simple. std::move() in that last line (mkDockbar.cpp:57) destroys the contents of the widget unique_ptr. When it tries to call widget->name(), things break. The fix, of course, is trivial:

        auto name = widget->name();
        return this->addDock(name, icon, std::move(widget));
alexeyknyshev commented 9 years ago

auto name = widget->name();

Not resolves problem. Because signature of this function:

const string &Widget::name()

which in this case returns reference to temporary and leads to segfault

See fix in a pull request https://github.com/novembermonk/kiui/pull/28 Please, merge Regards, Alexey Knyshev

mrzv commented 9 years ago

That's strange. Not only do I not see the second segfault, but the way I understand auto type deduction, in

auto name = widget->name();

auto gets resolved to string and one simply gets a local copy.

alexeyknyshev commented 9 years ago

auto is resolved into direct return type which in this case in

const string &

And it is reference to string object in widget, so then it is going to be destroyed when widget is destroyed.

mrzv commented 9 years ago

I really don't think that's how auto type deduction works. Here's a simple test for you, compile and try for yourself.

#include <type_traits>

struct A
{
    struct B {};
    const B& f () { return b; }
    B b;
};

int main()
{
    A a;
    auto x = a.f();
    static_assert(std::is_same<decltype(x), A::B>::value,        "A::B");
    static_assert(std::is_same<decltype(x), const A::B&>::value, "const A::B&");
}

Also worth noting, widget doesn't get destroyed anywhere in this function; a unique_ptr to it simply gets moved. So even if name was a const-reference, nothing would break — the addresses don't change.

alexeyknyshev commented 9 years ago

Sorry, was asleep while writting comment about auto. Everything is ok with:

auto name = widget->name()

Regrads, Alexey Knyshev

alexeyknyshev commented 9 years ago

BTW, my pull request is ok and may be merged :smile:

hugoam commented 9 years ago

Aaah yeah, the order isn't guaranteed to be ->name before std::move. Makes a lot of sense. Thanks for finding it while I'm away from computer.