Adding items to the Kodi library makes Kodi crash

Moderators: mdrjr, odroid

Adding items to the Kodi library makes Kodi crash

Unread postby thehip » Sun Apr 03, 2016 10:43 pm

Hi everyone !

It's me again, trying to get Kodi to work on ArchLinuxARM on my Odroid-XU ! In the last episode, we fixed CEC after audio, so Kodi now boots up and is usable, BUT it seems that adding new items to the Kodi library makes Kodi crash !

In order to reproduce the bug, just compile Kodi from Oversun's source, using appropriate flags - here are mine :
Code: Select all
./configure --enable-libcec \
--disable-x11 \
--enable-alsa \
--disable-pulse \
--enable-non-free \
--disable-vaapi \
--disable-vdpau \
--enable-hybris \
--enable-optimizations \
--enable-codec=mfc \
--enable-libbluray \
--disable-lirc


Then add to the library a folder containing a few movies -at least this type of item caused the bug on my side-, wait for it to finish scanning the folder... It crashes straight after the end of the scan. A bit unexpected behavior, but still that might be just a crash for any other reason. So let's try to launch Kodi again. The logo appears on the screen, CEC gets initialized, and just when the home screen wallpaper appears (you know, the blue bubbles), Kodi crashes because of a segmentation fault. How disappointing !

Nothing special to notice in the log files, except the last line which is ALWAYS the same, proving something goes wrong straight after it :
Code: Select all
[.... blah blah blah, initalizing shaders, CEC, ....]
12:06:46 T:3021590528   DEBUG: ------ Window Init (DialogKaiToast.xml) ------
12:06:46 T:3021590528   DEBUG: Window DialogKaiToast.xml was already loaded
12:06:46 T:3021590528   DEBUG: Alloc resources: 0.01ms
12:06:46 T:2811229024   DEBUG: RunQuery took 34 ms for 10 items query: select * from movie_view  ORDER BY dateAdded desc, idMovie desc LIMIT 10


The very latest line of the log is a query made to the database. It aims at getting the 10 latest movies added to the hard drive, in order to provide quick access to them through thumbnails. The database is not corrupt, as opening it through SQLite (it is locacted in /home/me/.kodi/userdata/Database/MyVideos99.db) and executing the request works properly (in fact, the log files indicate us that it worked properly as it gives us the time taken to run it).

That said, requesting a backtrace through GDB (wooo, debugging !) seems to indicate something goes wrong with the database :
Code: Select all
#0  0xb564cf20 in std::local_Rb_tree_decrement (__x=0x171a764 <_ZStL19piecewise_construct>) at /build/gcc/src/gcc-5-20160209/libstdc++-v3/sr/c++98/tree.cc:98
#1  0x0045d9d4 in std::_Rb_tree_iterator<std::pair<Field const, CVariant> >::operator-- (this=<synthetic pointer>) at /usr/include/c++/5.3./bits/stl_tree.h:220
#2  std::_Rb_tree<Field, std::pair<Field const, CVariant>, std::_Select1st<std::pair<Field const, CVariant> >, std::less<Field>, std::allocator<std::pair<Field const, CVariant> > >::_M_get_insert_hint_unique_pos (__k=@0xb2b99fb8: -1296476504, __position=..., this=0xabff3c50) at /usr/include/c++/5.3.0/bits/stl_tree.h:1924
#3  std::_Rb_tree<Field, std::pair<Field const, CVariant>, std::_Select1st<std::pair<Field const, CVariant> >, std::less<Field>, std::allocator<std::pair<Field const, CVariant> > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<Field&&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<Field const, CVariant> >, std::piecewise_construct_t const&, std::tuple<Field&&>&&, std::tuple<>&&) (this=0xabff3c50, this@entry=0xb41a0aa4, __pos=...,
    __pos@entry=<error reading variable: Cannot access memory at address 0x10>) at /usr/include/c++/5.3.0/bits/stl_tree.h:2174
#4  0x00b51848 in std::map<Field, CVariant, std::less<Field>, std::allocator<std::pair<Field const, CVariant> > >::operator[](Field&&) (
    __k=<unknown type in /usr/local/lib/kodi/kodi.bin, CU 0x680c5f3, DIE 0x683ff10>, this=0xb41a0aa4) at /usr/include/c++/5.3.0/bits/stl_map.h:502
#5  DatabaseUtils::GetDatabaseResults (mediaType="", fields=std::vector of length 0, capacity 0, dataset=std::unique_ptr<dbiplus::Dataset> containing 0xac4f0030,
    results=std::vector of length 0, capacity 10) at DatabaseUtils.cpp:374
#6  0x00b98c34 in SortUtils::SortFromDataset (sortDescription=..., mediaType="movie", dataset=std::unique_ptr<dbiplus::Dataset> containing 0xac4f0030,
    results=std::vector of length 0, capacity 10) at SortUtils.cpp:758
#7  0x0041d444 in CVideoDatabase::GetMoviesByWhere (
    this=0x41d444 <CVideoDatabase::GetMoviesByWhere(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CDatabase::Filter const&, CFileItemList&, SortDescription const&)+780>, this@entry=0xabff544c, strBaseDir=<error reading variable: Cannot create a lazy string with address 0x0, and a non-zero length.>,
    filter=..., items=..., sortDescription=...) at VideoDatabase.cpp:6162
#8  0x0041e3c8 in CVideoDatabase::GetRecentlyAddedMoviesNav (this=this@entry=0xabff544c,
    strBaseDir=<error reading variable: Cannot create a lazy string with address 0x0, and a non-zero length.>, items=..., limit=limit@entry=10) at VideoDatabase.cpp:6474
#9  0x00b78e80 in CRecentlyAddedJob::UpdateVideo () at RecentlyAddedJob.cpp:60
#10 0x00b84168 in CRecentlyAddedJob::DoWork (this=0x2fb8e00) at RecentlyAddedJob.cpp:354
#11 0x00b5eb80 in CJobWorker::Process (this=0x2fde460) at JobManager.cpp:66
#12 0x0168e21c in CThread::Action (this=0x2fde460) at Thread.cpp:221
#13 0x0168e4ec in CThread::staticThread (data=0x2fde460) at Thread.cpp:131
#14 0xb68a0f78 in start_thread () from /usr/lib/libpthread.so.0
#15 0xb5529a80 in ?? () from /usr/lib/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

In fact, it is probably not the above request, but it is likely to be something executed right after. The backtrace is not very helpful about it in fact, but it seems the bug occurs when Kodi attempts sorting the results.

This seems to be a common issue as it a was also reported on another board with another OS, so I think it might be worth investigating !

Thanks in advance for your help !

thehip
thehip
 
Posts: 18
Joined: Mon Sep 01, 2014 4:51 am
languages_spoken: english, french
ODROIDs: XU (Lite)

Re: Adding items to the Kodi library makes Kodi crash

Unread postby OverSun » Mon Apr 04, 2016 12:19 am

Yeah, the thing is that it's not odroid related.
It's some internal C++ operations that fail because of two reasons:
1) Not officially supported architecture (arm64)
2) Not officially supported compiler.
Rising that questions on official forum will bring you exactly this answer, and nobody are going to bother looking into that.

So I would suggest you at first turn off optimisations. "enable-optimisations" for gcc 5 is known to cause core dumps. If that doesn't help - compile using gcc 4.
And by the way you will have to clear your settings directory ".kodi" in your home folder, because it already contains a database that is going to crash your kodi on start regardless of how good compiled it is.
User avatar
OverSun
 
Posts: 1238
Joined: Mon Apr 29, 2013 5:12 pm
languages_spoken: english

Re: Adding items to the Kodi library makes Kodi crash

Unread postby thehip » Tue Apr 05, 2016 12:55 am

Thank you for your answer. You're right, this issue was raised in the official forums. Disabling optimizations did not do the trick with GCC 5.3, I got the exact same error. By the way, please note that this error does not occur at the exact same place than in Kodi forum's report, but rather in the sorting routine you can see in the first post's backtrace.

Your first point about architecture seems weird to me, as the Odroid-XU relies on an armv7h architecture which should be supported because it is the same as Raspberry pi.
That said, I tried to compile a GCC version from the 4.x branch (gcc 4.9.3). It didn't work, because everyone knows I can't type configure and make commands properly... [Understand : this *@{#~% did not want to compile, and the errors came after an hour of build at each attempt.] Guess I have to become a C++ guru before my next try. :D

Anyway, at least I read the GCC docs, and found out something helpful (yes, it is possible to find something helpful in the docs, try it out!). Indeed, GCC 5.1 introduced a new ABI (an interface binaries use to communicate with each other, here it is for libstdc++) and kindly set this as a default. (Thanks guys, that's genius !) And that's where the bug comes from : the new ABI seems to break Kodi, at least for the moment. But there's still a good news : it is possible to disable it, the old ABI is still here for compatibility purposes ! It just requires a little flag called "--disable-libstdcxx-dual-abi".

Right, I have got absolutely no Idea about where to put this flag in the configure script to get it included in the compilation process, so as usual I did it the hacky way : configure first, then hack the Makefiles so that your flag gets in for sure. After typing the configure command from the first post (you can even keep optimizations !), edit Makefile.include (it is at the root of Kodi's source, in the same directory as configure or boostrap). Replace the following line :
Code: Select all
CXXFLAGS_FOR_BUILD+=-g -O2
By :
Code: Select all
CXXFLAGS_FOR_BUILD+=-g -O2 --disable-libstdcxx-dual-abi

Then build Kodi as usual ('make -j4") and install it ("sudo make install"). You're done, there's even no need to clear the .kodi files ! Just launch Kodi as usual : "/usr/local/lib/kodi/kodi.bin".

Maybe we should report this issue to GCC developers, or the Kodi team as we now have a fix ?
thehip
 
Posts: 18
Joined: Mon Sep 01, 2014 4:51 am
languages_spoken: english, french
ODROIDs: XU (Lite)

Re: Adding items to the Kodi library makes Kodi crash

Unread postby OverSun » Tue Apr 05, 2016 2:16 am

Sorry, got lost in architectures last time, a lot of stuff is about C2 right now, didn't check the forum name.
Good that it worked for you in the end.
You could put the flag into environment variable, like this:
CXXFLAGS=--disable-libstdcxx-dual-abi ./configure
and it will be added to every g++ command. Same goes for CFLAGS to be added to plain gcc.
you can also export it globally like:
export CXXFLAGS=--disable-libstdcxx-dual-abi
and then every configure script you are going to try will pick it up.

I don't think any report is going to affect anyone, this forum is full of useful info on how to deal with kodi, new codecs and a lot of fixes. Every time we tried to propose anything of that to mainline kodi, it was ending up crashing against snob wall of kodi moderators. So we stopped trying. They are on their own wave, probably they know better what is best for their software.
User avatar
OverSun
 
Posts: 1238
Joined: Mon Apr 29, 2013 5:12 pm
languages_spoken: english

Re: Adding items to the Kodi library makes Kodi crash

Unread postby thehip » Sat May 07, 2016 5:43 am

Thank you for the cleaner way to put my flag into to compilation. I just tried it out and realized that setting this flag made the configure call fail when checking libraries :
Code: Select all
checking boost/circular_buffer.hpp usability... no
checking boost/circular_buffer.hpp presence... yes
configure: WARNING: boost/circular_buffer.hpp: present but cannot be compiled
configure: WARNING: boost/circular_buffer.hpp:     check for missing prerequisite headers?
configure: WARNING: boost/circular_buffer.hpp: see the Autoconf documentation
configure: WARNING: boost/circular_buffer.hpp:     section "Present But Cannot Be Compiled"
configure: WARNING: boost/circular_buffer.hpp: proceeding with the compiler's result
configure: WARNING:     ## ---------------------------------- ##
configure: WARNING:     ## Report this to http://trac.kodi.tv ##
configure: WARNING:     ## ---------------------------------- ##
checking for boost/circular_buffer.hpp... no
configure: error: Could not find a required library. Please see the README for your platform.

I think something goes wrong with libboost, the compiler and the flag (maybe libboost was not compiled with this flag, but isn't this a simple C++ header ?). Anyway, if I just set CXXFLAGS_FOR_BUILD, not CXXFLAGS, it works properly. So the "correct" call for configure ends up being :
Code: Select all
CXXFLAGS_FOR_BUILD="-g -O2 --disable-libstdcxx-dual-abi" ./configure [your flags]

Just wanted to share this finding, in case it helps someone. :)
thehip
 
Posts: 18
Joined: Mon Sep 01, 2014 4:51 am
languages_spoken: english, french
ODROIDs: XU (Lite)


Return to Other OS

Who is online

Users browsing this forum: No registered users and 2 guests