frostwire / frostwire-jlibtorrent

A swig Java interface for libtorrent by the makers of FrostWire. Develop libtorrent based apps with the joy of coding in Java.
http://www.frostwire.com
MIT License
451 stars 138 forks source link

[android/arm crash] libtorrent::piece_index::bitfield_get_bit() #181

Closed gubatron closed 6 years ago

gubatron commented 6 years ago

I'm trying to obtain whether or not a piece has been downloaded the following way, perhaps I'm misunderstanding the API and I shouldn't be passing the piece index there.

private static int getTotalPiecesDownloaded(final PieceIndexBitfield pieces, final int totalPieces) {
        if (pieces == null || totalPieces <= 0) {
            return 0;
        }
        long a = SystemClock.currentThreadTimeMillis();
        int totalDownloaded = 0;
        for (int i = 0; i < totalPieces; i++) { //we have a freeze, grr, i believe it's due to the scanning of the large ISO file, not yet deleted fully
            totalDownloaded += (pieces.getBit(i) ? 1 : 0);
        }
        long b = SystemClock.currentThreadTimeMillis();
        System.out.println("getTotalPiecesDownloaded() -> " + totalDownloaded + " counted in " + (b - a) + " ms");
        return totalDownloaded;
    }

Crash:

10-28 21:48:18.077 17949 17949 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-28 21:48:18.077 17949 17949 F DEBUG   : Build fingerprint: 'samsung/dreamqltesq/dreamqltesq:7.0/NRD90M/G950USQU1AQHD:user/release-keys'
10-28 21:48:18.078 17949 17949 F DEBUG   : Revision: '12'
10-28 21:48:18.078 17949 17949 F DEBUG   : ABI: 'arm'
10-28 21:48:18.078 17949 17949 F DEBUG   : pid: 16534, tid: 16534, name: ostwire.android  >>> com.frostwire.android <<<
10-28 21:48:18.078 17949 17949 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4
10-28 21:48:18.078 17949 17949 F DEBUG   :     r0 80000000  r1 00000000  r2 80000000  r3 00000000
10-28 21:48:18.078 17949 17949 F DEBUG   :     r4 ed3a5aac  r5 00000004  r6 00000004  r7 ffc32408
10-28 21:48:18.078 17949 17949 F DEBUG   :     r8 ffc32408  r9 eec05900  sl 00000000  fp ffc3238c
10-28 21:48:18.078 17949 17949 F DEBUG   :     ip d149e5d0  sp ffc322e0  lr d22df04b  pc d149e5f4  cpsr 600d0010
10-28 21:48:18.087 17949 17949 F DEBUG   : 
10-28 21:48:18.087 17949 17949 F DEBUG   : backtrace:
10-28 21:48:18.088 17949 17949 F DEBUG   :     #00 pc 000cf5f4  /data/app/com.frostwire.android-1/lib/arm/libjlibtorrent.so (Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_piece_1index_1bitfield_1get_1bit+36)
10-28 21:48:18.088 17949 17949 F DEBUG   :     #01 pc 009b7049  /data/app/com.frostwire.android-1/oat/arm/base.odex (offset 0x930000)
10-28 21:48:18.674  4782  4782 D io_stats: !@   8,0 r 11895699 480380276 w 5357374 78314816 d 492279 59667872 f 1957019 2093948 iot 18383000 12378836 th 186360 0 0 pt 0 inp 0 0 384888.095
gubatron commented 6 years ago

so I understand now that pieces.count() does not return the total number of pieces, but precisely what I was trying to do here, all the bits set to 1.

Still, I need to figure out why it crashes when I ask for pieces.getBit(n) or pieces.swig().get_bit(n), perhaps the nth bit position does not correspond the the piece index.

gubatron commented 6 years ago

however, pieces.count() is always returning 0, even if the file is finished, when it's downloading, always returns 0.

I think the whole status.pieces() is broken.

gubatron commented 6 years ago

it looks as if those methods don't actually exist, or they cannot be found, at least not by the debugger, and when called in runtime this must be the reason for the crash.

screen shot 2017-10-28 at 11 09 26 pm

screen shot 2017-10-28 at 11 09 42 pm

same for other methods I tried using, like isAllSet isNoneSet

screen shot 2017-10-28 at 11 09 10 pm

screen shot 2017-10-28 at 11 08 59 pm