w00t-labs / libtorrent

Automatically exported from code.google.com/p/libtorrent
Other
0 stars 0 forks source link

Libtorrent RC2 crashes with minimal example on Android #627

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have compiled libtorrent RC2 for Android using the official NDK toolchain. 
The compiled .so file is included in the repository used below (in 
jni/libs/libtorrent/libtorrent-rasterbar.so), but I recommend you compile your 
own. It crashes with a segmentation fault on a minimal example.

Download and compile the simple android example:

1. Clone the HelloLibtorrent repository, and checkout the "simple" branch: 
https://github.com/rjagerman/HelloLibtorrent/tree/simple
2. Run   android update project -p . -t android-14
3. Modify jni/hello.cpp to refer to an existing .torrent file on your phone 
(you should manually place this .torrent file on your phone)
4. To compile, run   ./clean-and-build.sh
5. To install the app on a connected phone, run   ./install.sh

Run it on an Android device (I use a Sony Xperia Z) and you get a segmentation 
fault after a few seconds.

I have included the segmentation fault's backtrace using NDK's gdb:

(gdb) bt
#0  0x400cefa0 in tgkill () from 
/home/rolf/Projects/Android/tordroid/hello-libtorrent/obj/local/armeabi/libc.so
#1  0x400c49e4 in pthread_kill () from 
/home/rolf/Projects/Android/tordroid/hello-libtorrent/obj/local/armeabi/libc.so
#2  0x400c4bf8 in raise () from 
/home/rolf/Projects/Android/tordroid/hello-libtorrent/obj/local/armeabi/libc.so
#3  0x73f7e660 in assert_fail(char const*, int, char const*, char const*, char 
const*, int) () at assert.cpp:265
#4  0x7423a2d0 in libtorrent::torrent::~torrent() () at torrent.cpp:858
#5  0x7423a880 in libtorrent::torrent::~torrent() () at torrent.cpp:862
#6  0x741ec0c4 in void 
boost::checked_delete<libtorrent::torrent>(libtorrent::torrent*) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/checked_delete.hpp:34
#7  0x741f8554 in 
boost::detail::sp_counted_impl_p<libtorrent::torrent>::dispose() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/detail/sp_counted_impl.hpp:78
#8  0x73f474d8 in boost::detail::sp_counted_base::release() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/detail/sp_counted_base_spin.hpp:103
#9  0x73f475a0 in boost::detail::shared_count::~shared_count() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/detail/shared_count.hpp:371
#10 0x73f47dd8 in boost::shared_ptr<libtorrent::torrent>::~shared_ptr() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/shared_ptr.hpp:328
#11 0x740dbe20 in boost::_bi::value<boost::shared_ptr<libtorrent::torrent> 
>::~value() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/bind.hpp:112
#12 0x740dd108 in 
boost::_bi::storage1<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> > 
>::~storage1() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/storage.hpp:40
#13 0x74273ff0 in 
boost::_bi::storage2<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> 
>, boost::arg<1> >::~storage2()
    () at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/storage.hpp:93
#14 0x7427401c in 
boost::_bi::storage3<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> 
>, boost::arg<1>, boost::arg<2> >::~storage3() () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/storage.hpp:142
#15 0x742745f4 in 
boost::_bi::list3<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> >, 
boost::arg<1>, boost::arg<2> >::~list3() () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/bind.hpp:352
#16 0x74274624 in boost::_bi::bind_t<void, boost::_mfi::mf2<void, 
libtorrent::torrent, int, libtorrent::disk_io_job const&>, 
boost::_bi::list3<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> >, 
boost::arg<1>, boost::arg<2> > >::~bind_t() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/bind.hpp:864
#17 0x742a1ae0 in 
boost::detail::function::functor_manager<boost::_bi::bind_t<void, 
boost::_mfi::mf2<void, libtorrent::torrent, in
t, libtorrent::disk_io_job const&>, 
boost::_bi::list3<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> >, 
boost::arg<1>, boost::arg<2> > > 
>::manager(boost::detail::function::function_buffer const&, 
boost::detail::function::function_buffer&, 
boost::detail::function::functor_manager_operation_type, mpl_::bool_<false>) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/function/function_base.hpp:389
#18 0x7429b574 in 
boost::detail::function::functor_manager<boost::_bi::bind_t<void, 
boost::_mfi::mf2<void, libtorrent::torrent, int, libtorrent::disk_io_job 
const&>, 
boost::_bi::list3<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> >, 
boost::arg<1>, boost::arg<2> > > 
>::manager(boost::detail::function::function_buffer const&, 
boost::detail::function::function_buffer&, 
boost::detail::function::functor_manager_operation_type, 
boost::detail::function::function_obj_tag) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/function/function_base.hpp:412
#19 0x7429427c in 
boost::detail::function::functor_manager<boost::_bi::bind_t<void, 
boost::_mfi::mf2<void, libtorrent::torrent, int, libtorrent::disk_io_job 
const&>, 
boost::_bi::list3<boost::_bi::value<boost::shared_ptr<libtorrent::torrent> >, 
boost::arg<1>, boost::arg<2> > > 
>::manage(boost::detail::function::function_buffer const&, 
boost::detail::function::function_buffer&, 
boost::detail::function::functor_manager_operation_type) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/function/function_base.hpp:440
#20 0x73fdda48 in boost::detail::function::basic_vtable2<void, int, 
libtorrent::disk_io_job 
const&>::clear(boost::detail::function::function_buffer&) const () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/function/function_templ
ate.hpp:504
#21 0x73fd9d84 in boost::function2<void, int, libtorrent::disk_io_job 
const&>::clear() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/function/function_template.hpp:877
#22 0x73fd80f0 in boost::function2<void, int, libtorrent::disk_io_job 
const&>::~function2() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/function/function_template.hpp:759
#23 0x73fd6610 in boost::function<void (int, libtorrent::disk_io_job 
const&)>::~function() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/function/function_template.hpp:1048
#24 0x73fd6e30 in libtorrent::disk_io_job::~disk_io_job() () at 
../include/libtorrent/disk_io_thread.hpp:89
#25 0x73fd736c in std::pair<libtorrent::disk_io_job, int>::~pair() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/c++/4.8/bits/stl_pair.h:96
#26 0x73fdf658 in __gnu_cxx::new_allocator<std::pair<libtorrent::disk_io_job, 
int> >::destroy(std::pair<libtorrent::disk_io_job, int>*) () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/c++/4.8/ext/new_allocator.h:1
33
#27 0x73fdbc6c in std::_List_base<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >::_M_clear() () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/c++/4.8/bits/list.tcc:77
#28 0x73fd8784 in std::_List_base<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int>
> >::~_List_base() () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/c++/4.8/bits/stl_list.h:378
#29 0x73fd6dc0 in std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >::~list() () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/c++/4.8/bits/stl_list.h:438
#30 0x73fe3cb4 in void 
boost::checked_delete<std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > > 
>(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*) () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/checked_delete.hpp:34
#31 0x73fe9fd4 in 
boost::detail::sp_counted_impl_p<std::list<std::pair<libtorrent::disk_io_job, 
int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > > >::dispose() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/detail/sp_counted_impl.hpp:78
#32 0x73f474d8 in boost::detail::sp_counted_base::release() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/detail/sp_counted_base_spin.hpp:103
#33 0x73f475a0 in boost::detail::shared_count::~shared_count() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/detail/shared_count.hpp:371
#34 0x73fd7154 in 
boost::shared_ptr<std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > > >::~shared_ptr() () 
at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/smart_ptr/shared_ptr.hp
p:328
#35 0x73fcf450 in 
libtorrent::completion_queue_handler(std::list<std::pair<libtorrent::disk_io_job
, int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*) () at 
disk_io_thread.cpp:1338
#36 0x73fe9bc4 in void 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> 
>::operator()<void (*)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list0>(boost::_bi::type<void>, void 
(*&)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list0&, int) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/bind.hpp:253
#37 0x73fe9750 in boost::_bi::bind_t<void, void 
(*)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > 
>::operator()() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/bind_template.hpp:20
#38 0x73fe8ce4 in void 
boost::asio::asio_handler_invoke<boost::_bi::bind_t<void, void 
(*)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > > 
>(boost::_bi::bind_t<void, void 
(*)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), boost::_bi::list
1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > >&, ...) () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/handler_invoke_hoo
k.hpp:69
#39 0x73fe7000 in void 
boost_asio_handler_invoke_helpers::invoke<boost::_bi::bind_t<void, void 
(*)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > >, 
boost::_bi::bind_t<void, void (*)(std::list<std::pair<libtorrent::disk_io_job, 
int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > > 
>(boost::_bi::bind_t<void, void 
(*)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > >&, 
boost::_bi::bind_t<void, void (*)(std::list<std::pair<libtorrent::disk_io_job, 
int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > >&) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/detail/handler_invoke_helpers.hpp:37
#40 0x73fe42a0 in 
boost::asio::detail::completion_handler<boost::_bi::bind_t<void, void 
(*)(std::list<std::pair<libtorrent::disk_io_job, int>, 
std::allocator<std::pair<libtorrent::disk_io_job, int> > >*), 
boost::_bi::list1<boost::_bi::value<std::list<std::pair<libtorrent::disk_io_job,
 int>, std::allocator<std::pair<libtorrent::disk_io_job, int> > >*> > > 
>::do_complete(boost::asio::detail::task_io_service*, 
boost::asio::detail::task_io_service_operation*, boost::system::error_code 
const&, unsigned int) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/detail/completion_handler.hpp:68
#41 0x73f72ae4 in 
boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::ta
sk_io_service&, boost::system::error_code const&, unsigned int) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/detail/task_io_service_operation.hpp:38
#42 0x73f6dcc8 in 
boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_loc
k<boost::asio::detail::posix_mutex>&, 
boost::asio::detail::task_io_service_thread_info&, boost::system::error_code 
const&) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/detail/impl/task_io_service.ipp:384
#43 0x73f6d0e4 in 
boost::asio::detail::task_io_service::run(boost::system::error_code&) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/detail/impl/task_io_service.ipp:153
#44 0x73f608c4 in boost::asio::io_service::run(boost::system::error_code&) ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/impl/io_service.ipp:66
#45 0x741b1434 in libtorrent::aux::session_impl::main_thread() () at 
session_impl.cpp:4825
#46 0x74199818 in boost::_mfi::mf0<void, 
libtorrent::aux::session_impl>::operator()(libtorrent::aux::session_impl*) 
const ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/mem_fn_template.hpp:49
#47 0x7419424c in void 
boost::_bi::list1<boost::_bi::value<libtorrent::aux::session_impl*> 
>::operator()<boost::_mfi::mf0<void, libtorrent::aux::session_impl>, 
boost::_bi::list0>(boost::_bi::type<void>, boost::_mfi::mf0<void, 
libtorrent::aux::session_impl>&, boost::_bi::list0&, int) () at 
/usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/bind.hpp:253
#48 0x7419023c in boost::_bi::bind_t<void, boost::_mfi::mf0<void, 
libtorrent::aux::session_impl>, 
boost::_bi::list1<boost::_bi::value<libtorrent::aux::session_impl*> > 
>::operator()() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/bind/bind_template.hpp:20
#49 0x741f8798 in 
boost::asio::detail::posix_thread::func<boost::_bi::bind_t<void, 
boost::_mfi::mf0<void, libtorrent::aux::session_impl>, 
boost::_bi::list1<boost::_bi::value<libtorrent::aux::session_impl*> > > 
>::run() ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/detail/posix_thread.hpp:82
#50 0x73f653a4 in boost_asio_detail_posix_thread_function ()
    at /usr/local/gcc-4.8.0-arm-linux-androideabi/include/boost/asio/detail/impl/posix_thread.ipp:64
#51 0x400bebe4 in __thread_entry () from 
/home/rolf/Projects/Android/tordroid/hello-libtorrent/obj/local/armeabi/libc.so
#52 0x400bed5c in pthread_create () from 
/home/rolf/Projects/Android/tordroid/hello-libtorrent/obj/local/armeabi/libc.so
#53 0x00000000 in ?? ()

Original issue reported on code.google.com by rjager...@gmail.com on 4 Jun 2014 at 9:11

GoogleCodeExporter commented 9 years ago
This is part of a larger project with 8 full-time developers.
We have a subset of the TOR protocol operational on Android.
Key is trying to get Libtorrent downloads stable.

We also invested 4 months into the old RuTracker port of Libtorrent to Android, 
https://github.com/javto/Tribler-streaming#rutracker

Anonymous downloading on Android specs: 
https://github.com/Tribler/tribler/wiki/Anonymous-Downloading-and-Streaming-spec
ifications

Original comment by peer2p...@gmail.com on 5 Jun 2014 at 9:26

GoogleCodeExporter commented 9 years ago
that's an assert. those line numbers in torrent.cpp don't line up for me. 
what's the output?

Original comment by arvid.no...@gmail.com on 6 Jun 2014 at 4:36

GoogleCodeExporter commented 9 years ago
Thank you for your quick response!
The line torrent.cpp:858 is inside torrent::~torrent() and contains the 
following assert:

TORRENT_ASSERT(m_abort);

I'm currently working on obtaining the assertion output, since android phones 
tend to be very restrictive about writing log files for applications... I will 
get back to you about this as soon as I can.

Original comment by rjager...@gmail.com on 6 Jun 2014 at 7:59

GoogleCodeExporter commented 9 years ago
Dear arvid,

Thanks for the response. We have redirected the stderr from libtorrent to 
logcat, and we get the following output:

V/stderr (22152): assertion failed. Please file a bugreport at 
http://code.google.com/p/libtorrent/issues
V/stderr (22152): Please include the following information:
V/stderr (22152):
V/stderr (22152): version: 1.0.0.0
V/stderr (22152): $Rev: 9739 $
V/stderr (22152):
V/stderr (22152): file: 'torrent.cpp'
V/stderr (22152): line: 858
V/stderr (22152): function: virtual libtorrent::torrent::~torrent()
V/stderr (22152): expression: m_abort
V/stderr (22152):
V/stderr (22152):
V/stderr (22152): stack:
V/stderr (22152): 

Do you have any idea why this assert could possibly fail?

Thanks!

Original comment by mdmartij...@gmail.com on 6 Jun 2014 at 10:08

GoogleCodeExporter commented 9 years ago
For clarity's sake, here is how we compiled libtorrent RC2 for android:

1) We have set up the official android NDK toolchain and created a custom 
toolchain at /usr/local/gcc-4.8.0-arm-linux-androideabi/
We set PATH, CC and CXX to point to this toolchain and set some other variables 
that we can use during our build process:

    export SYSROOT=$ANDROIDNDK/platforms/android-14/arch-arm
    export PATH=/usr/local/gcc-4.8.0-arm-linux-androideabi/bin:$PATH
    export CC=arm-linux-androideabi-gcc
    export CXX=arm-linux-androideabi-g++
    export CROSSHOST=arm-linux-androideabi
    export CROSSHOME=/usr/local/gcc-4.8.0-arm-linux-androideabi

2) After downloading boost 1.55.0, we have compiled boost-system and 
boost-filesystem using the NDK toolchain. This results in libboost_system.a and 
libboost_filesystem.a, which are installed in 
/usr/local/gcc-4.8.0-arm-linux-androideabi/lib 

3) Next, we download openssl-1.0.1g and compile it using the NDK toolchain. 
This results in libcrypto.a and libssl.a, which are also installed in 
/usr/local/gcc-4.8.0-arm-linux-androideabi/lib 

3) We've downloaded and extracted "libtorrent-rasterbar-1.0.0-RC2.tar.gz" from 
http://sourceforge.net/projects/libtorrent/files/libtorrent/

4) To configure libtorrent, we run:

    ./configure --host=$CROSSHOST --prefix=$CROSSHOME --with-boost=$CROSSHOME --with-boost-libdir=$CROSSHOME/lib --enable-shared --disable-static --enable-debug=yes --enable-logging=yes

A side note here, we modify src/Makefile on line 576 so it removes the 
versioning information in the .so file which doesn't play nice with Android:
    libtorrent_rasterbar_la_LDFLAGS = -avoid-version

5) And to finally compile libtorrent, we use:

    make && make install

Which results in a libtorrent.so for Android that we can use in our application.

Original comment by rjager...@gmail.com on 6 Jun 2014 at 12:26

GoogleCodeExporter commented 9 years ago
This assert makes sure that every torrent object is properly shut down before 
being destructed. This is meant to happen by torrent::abort().

This is called by session_impl::abort() or session_impl::remove_torrent(). 
Those are the main paths through which a torrent should be destroyed. In your 
case, it doesn't sound like you intend to remove the torrent.

Is it possible that the chip you run on or its compiler has a bug with atomic 
operations? I have seen this on embedded devices before. If so, that could 
explain this error by the boost::shared_ptr<> failing to keep the reference 
counter consistent, and deleting the object prematurely.

try to build with "BOOST_SP_USE_PTHREADS" to test this theory. That will make 
boost::shared_ptr use a mutex instead of atomic operations.

Original comment by arvid.no...@gmail.com on 6 Jun 2014 at 2:12

GoogleCodeExporter commented 9 years ago
Dear Arvid,

Thanks for the helpful comment. We're going to try that and we will post our 
findings!

Original comment by mdmartij...@gmail.com on 6 Jun 2014 at 2:15

GoogleCodeExporter commented 9 years ago
We tried to compile it with the BOOST_SP_USE_PTHREADS define but that dit not 
work, our application still crashes with the same stack trace. Do you have any 
other idea what we could try to get it working? Maybe there is another cause 
that deletes the object prematurely.

Thanks!

Original comment by mdmartij...@gmail.com on 8 Jun 2014 at 9:27

GoogleCodeExporter commented 9 years ago
are you adding torrents by URL? there is a kind of "dummy" torrent object added 
to represent the download, and it's then replaced by the actual one once it's 
downloaded, parsed and we know the info-hash. That is the only other place a 
torrent object is deleted I can think of.

Original comment by arvid.no...@gmail.com on 8 Jun 2014 at 9:23

GoogleCodeExporter commented 9 years ago
No, we have a .torrent file on the Android device which we load in our code. 
(for testing we are using the Ubuntu 14.04 torrent file).

Could this mean that the issue is indeed caused by Boost's shared pointers 
failing to hold a reference to the Torrent object? Are there any other known 
issues with that, especially on mobile devices?

Original comment by mdmartij...@gmail.com on 8 Jun 2014 at 9:34

GoogleCodeExporter commented 9 years ago
We have probably fixed the issue.

It was indeed caused by the shared pointers but somehow it kept using the 
sp_counted_base_spin.hpp file for it's include while it should use 
sp_counted_base_pt.hpp. We simply changed the #include statements of the 
sp_counted_base_spin.hpp by sp_counted_base_pt.hpp. It seems to run stable now 
on the Android device.

So your theory was right indeed, using the BOOST_SP_USE_PTHREAD flag should fix 
this issue, however, we had to modify the code in Boost itself which is not a 
good style, but it works for us. Thanks for your help with this. If we run into 
any other problems, we come back to you. Thanks for your help.

Original comment by mdmartij...@gmail.com on 9 Jun 2014 at 4:35

GoogleCodeExporter commented 9 years ago
when building libtorrent, you can specify (on the bjam command line): 
define=BOOST_SP_USE_PTHREAD and you would also have to specify -a to force a 
rebuild all. you would probably also have to specify this in your own code, 
that may interact with shared_ptr

Original comment by arvid.no...@gmail.com on 9 Jun 2014 at 11:16

GoogleCodeExporter commented 9 years ago
I ran into the same issue on my Nexus 5. What threw me off for a little bit was 
the #define suggested is missing an "S" at the end.

BOOST_SP_USE_PTHREADS is the correct one.

Line 29 of sp_counted_base.hpp

#elif defined( BOOST_SP_USE_PTHREADS )
# include <boost/smart_ptr/detail/sp_counted_base_pt.hpp>

Original comment by d...@doog.us on 10 Nov 2014 at 4:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
does libtorrent have any setpiecepriorities() functions? for sequential 
download / torrent streaming.

i see popcorn time is using it in their application - is this their custom work?

thanks!

Original comment by ole.stub...@gmail.com on 10 Nov 2014 at 2:45

GoogleCodeExporter commented 9 years ago
yes:

   http://libtorrent.org/reference-Core.html#prioritize_pieces()

but for streaming, you should use:

   http://libtorrent.org/reference-Core.html#set_piece_deadline()

Original comment by arvid.no...@gmail.com on 10 Nov 2014 at 3:58