Closed alexeyknyshev closed 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)
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
Exactly same bt on very fresh installation of debian 9 Vote up. It's a blocker on Linux.
I'll investigate, but if someone on the system where it fails, can step the debugger to find a plausible origin, it's welcome.
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));
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
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.
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.
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.
Sorry, was asleep while writting comment about auto. Everything is ok with:
auto name = widget->name()
Regrads, Alexey Knyshev
BTW, my pull request is ok and may be merged :smile:
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.
gdb bt:
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