Author Topic: tgkill  (Read 966 times)

dieppa

  • Posts: 33
tgkill
« on: 15 Jan '18 - 11:05 »
Hello,

Several devices are crashing describing the following stacktrace from Google play console:

Samsung Galaxy J5 (j5nlte), 1536MB RAM, Android 6.0
Informe 1 de 5

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 0 >>> com.energysistem.energyMusic <<<

backtrace:
  #00  pc 0000000000044310  /system/lib/libc.so (tgkill+12)
  #01  pc 0000000000041f11  /system/lib/libc.so (pthread_kill+32)
  #02  pc 000000000001ba13  /system/lib/libc.so (raise+10)
  #03  pc 0000000000018c81  /system/lib/libc.so (__libc_android_abort+34)
  #04  pc 0000000000016840  /system/lib/libc.so (abort+4)
  #05  pc 000000000031eb45  /system/lib/libart.so (_ZN3art7Runtime5AbortEv+200)
  #06  pc 00000000000f3acd  /system/lib/libart.so (_ZN3art10LogMessageD2Ev+2212)
  #07  pc 00000000001d5185  /system/lib/libart.so (_ZN3art22IndirectReferenceTable3AddEjPNS_6mirror6ObjectE+228)
  #08  pc 000000000024d361  /system/lib/libart.so (_ZN3art9JavaVMExt12AddGlobalRefEPNS_6ThreadEPNS_6mirror6ObjectE+28)
  #09  pc 0000000000283c6d  /system/lib/libart.so (_ZN3art3JNI12NewGlobalRefEP7_JNIEnvP8_jobject+212)
  #10  pc 000000000000d1ad  /data/app/com.energysistem.energyMusic-1/lib/arm/libbass.so
  #11  pc 000000000000d1c9  /data/app/com.energysistem.energyMusic-1/lib/arm/libbass.so
  #12  pc 0000000000020703  /data/app/com.energysistem.energyMusic-1/lib/arm/libbass.so (Java_com_un4seen_bass_BASS_BASS_1ChannelSetSync+58)
  #13  pc 0000000000e241eb  /data/app/com.energysistem.energyMusic-1/oat/arm/base.odex

Any clue of what could be going on?

Thanks.

EDIT:

I suspect it's related to an increasing amount of references to Java objects. I will release a patch in the next few hours. I will share with you the results!
« Last Edit: 15 Jan '18 - 13:00 by dieppa »

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: tgkill
« Reply #1 on: 15 Jan '18 - 15:26 »
Yes, from the "NewGlobalRef" in that call stack, it looks like it may well be a case of too many global Java object references. In this case, it'll be adding a reference to your SYNCPROC in a BASS_ChannelSetSync call, so you could check how many syncs you're setting and if you can reduce that, eg. perhaps some are no longer needed and can be freed via BASS_ChannelRemoveSync?

dieppa

  • Posts: 33
Re: tgkill
« Reply #2 on: 16 Jan '18 - 16:41 »
Hi Ian,

Yes, I did it, it seems to be working so far.

Thanks!

gautam

  • Posts: 1
tgkill
« Reply #3 on: 15 Mar '18 - 06:20 »
pid: 0, tid: 0 >>> com.package.name <<<

backtrace:
  #00  pc 000000000004a868  /system/lib/libc.so (tgkill+12)
  #01  pc 0000000000047fe3  /system/lib/libc.so (pthread_kill+34)
  #02  pc 000000000001dbad  /system/lib/libc.so (raise+10)
  #03  pc 0000000000019321  /system/lib/libc.so (__libc_android_abort+34)
  #04  pc 0000000000017388  /system/lib/libc.so (abort+4)
  #05  pc 00000000002a1ab1  /data/app/com.google.android.webview-1/lib/arm/libwebviewchromium.so

I found this issues in Samsung Galaxy J3(2016) (j3ltevzw), 1536MB RAM, Android 7.1

please identified issue and give me solution.

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: tgkill
« Reply #4 on: 15 Mar '18 - 16:46 »
That crash does not appear to be related to BASS.

dieppa

  • Posts: 33
Re: tgkill
« Reply #5 on: 6 Jul '18 - 08:46 »
Hi Ian,

Once implemented the streaming may devices are crashing again, but this time it doens't seem to be the SYNCPROC.

Ayer, 8:00 en la versión 20059 de la app
bq Aquaris V (nappa), Android 7.1
Informe 1

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 0 >>> com.energysistem.energyMusic <<<

backtrace:
  #00  pc 0000000000049d78  /system/lib/libc.so (tgkill+12)
  #01  pc 00000000000474f3  /system/lib/libc.so (pthread_kill+34)
  #02  pc 000000000001d745  /system/lib/libc.so (raise+10)
  #03  pc 0000000000019281  /system/lib/libc.so (__libc_android_abort+34)
  #04  pc 00000000000172e8  /system/lib/libc.so (abort+4)
  #05  pc 000000000031af89  /system/lib/libart.so (_ZN3art7Runtime5AbortEPKc+328)
  #06  pc 00000000000b5285  /system/lib/libart.so (_ZN3art10LogMessageD2Ev+1132)
  #07  pc 0000000000334f6f  /system/lib/libart.so (_ZNK3art6Thread39AssertNoPendingExceptionForNewExceptionEPKc+642)
  #08  pc 000000000033768f  /system/lib/libart.so (_ZN3art6Thread17ThrowNewExceptionEPKcS2_+10)
  #09  pc 0000000000107b8b  /system/lib/libart.so (_ZN3artL14ThrowExceptionEPKcPNS_6mirror5ClassES1_PSt9__va_list+702)
  #10  pc 000000000010ac27  /system/lib/libart.so (_ZN3art34ThrowNullPointerExceptionFromDexPCEv+322)
  #11  pc 00000000003ff787  /system/lib/libart.so (MterpInvokeVirtualQuick+350)
  #12  pc 00000000000a0594  /system/lib/libart.so (ExecuteMterpImpl+29972)
  #13  pc 00000000001ca9af  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+290)
  #14  pc 00000000001cf481  /system/lib/libart.so (_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameE+92)
  #15  pc 00000000003f47f7  /system/lib/libart.so (artQuickToInterpreterBridge+706)
  #16  pc 00000000000ae413  /system/lib/libart.so (art_quick_to_interpreter_bridge+34)
  #17  pc 00000000000a99c1  /system/lib/libart.so (art_quick_invoke_stub_internal+64)
  #18  pc 00000000004052f1  /system/lib/libart.so (art_quick_invoke_stub+232)
  #19  pc 00000000000b0c55  /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+136)
  #20  pc 0000000000315ef9  /system/lib/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+56)
  #21  pc 0000000000316ea9  /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDSt9__va_list+256)
  #22  pc 0000000000267ee9  /system/lib/libart.so (_ZN3art3JNI14CallIntMethodVEP7_JNIEnvP8_jobjectP10_jmethodIDSt9__va_list+444)
  #23  pc 000000000000d50d  /data/app/com.energysistem.energyMusic-2/lib/arm/libbass.so
  #24  pc 000000000000db13  /data/app/com.energysistem.energyMusic-2/lib/arm/libbass.so
  #25  pc 000000000000ac65  /data/app/com.energysistem.energyMusic-2/lib/arm/libbass.so
  #26  pc 0000000000018a59  /data/app/com.energysistem.energyMusic-2/lib/arm/libbass.so
  #27  pc 000000000002b4a9  /data/app/com.energysistem.energyMusic-2/lib/arm/libbass.so
  #28  pc 000000000002c39b  /data/app/com.energysistem.energyMusic-2/lib/arm/libbass.so (BASS_StreamCreateFileUser+68)
  #29  pc 000000000002c3d1  /data/app/com.energysistem.energyMusic-2/lib/arm/libbass.so (Java_com_un4seen_bass_BASS_BASS_1StreamCreateFileUser+30)
  #30  pc 0000000000b3345f  /data/app/com.energysistem.energyMusic-2/oat/arm/base.odex

dieppa

  • Posts: 33
Re: tgkill
« Reply #6 on: 6 Jul '18 - 08:50 »
This is my BassPlayer class

Code: [Select]
/**
 * Created by HMD on 28/11/2017.
*/
public class BassPlayer implements IPlayer {

    private static final String TAG = BassPlayer.class.getCanonicalName();

    private int playerChannel;
    private int endSyncHandler;
    private final int frequency = 44100;
    private final int ALLOC_SIZE = 2048;

    /**
     * Player callback listener
     */
    private OnIPlayerCallback onIPlayerCallback;
    /**
     * Current playing song
     */
    private SongPlayerModel playingSong;
    /**
     * Equalizer instance
     */
    private IEqualizer equalizer;

    private StreamAdapterBuilder streamAdapterBuilder;

    private StreamAdapter streamAdapter;

    public BassPlayer(StreamAdapterBuilder streamAdapterBuilder) {
        BASS.BASS_SetConfig(BASS.BASS_CONFIG_FLOATDSP, 1);
        this.streamAdapterBuilder = streamAdapterBuilder;
    }

    @Override
    public int initialize() {
        if (!BASS.BASS_Init(-1, frequency, 0)) {
            return IPlayer.INVALID_STATE_ERROR;
        }

        if (BASS.BASS_PluginLoad("libbassflac.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbassdsd.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbasswv.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbassmidi.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbassalac.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbassopus.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbass_aac.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbass_ape.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbass_mpc.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbass_tta.so", 0) == 0 ||
            BASS.BASS_PluginLoad("libbasshls.so", 0) == 0)
            Log.e(TAG, "Not all libraries were successfully loaded");

        return IPlayer.SUCCESS;
    }

    @Override
    public int play() {
        if (BASS.BASS_ChannelPlay(this.playerChannel, false)) {
            if (onIPlayerCallback != null)
                onIPlayerCallback.onStartPlaying();
            return SUCCESS;
        }
        else
            return OPERATION_ERROR;
    }

    @Override
    public int pause() {
        if (BASS.BASS_ChannelPause(this.playerChannel)) {
            if (onIPlayerCallback != null)
                onIPlayerCallback.onPaused();
            return SUCCESS;
        }
        else
            return OPERATION_ERROR;
    }

    @Override
    public int stop() {
        if (BASS.BASS_ChannelStop(this.playerChannel)) {
            if (onIPlayerCallback != null)
                onIPlayerCallback.onStopped();
            return SUCCESS;
        }
        else
            return OPERATION_ERROR;
    }

    @Override
    public int seekTo(double time) {
        long amountOfBytes = BASS.BASS_ChannelSeconds2Bytes(this.playerChannel, time / 1000);
        if (BASS.BASS_ChannelSetPosition(this.playerChannel, amountOfBytes, BASS.BASS_POS_BYTE))
            return SUCCESS;
        else {
            Log.e(TAG, BASS.BASS_ErrorGetCode() + "");
            return OPERATION_ERROR;
        }
    }

    @Override
    public int getCurrentPositionInSong() {
        long currentPosition = BASS.BASS_ChannelGetPosition(this.playerChannel, BASS.BASS_POS_BYTE);
        return  (int) (BASS.BASS_ChannelBytes2Seconds(this.playerChannel, currentPosition) * 1000);
    }

    @Override
    public ByteBuffer getFFT() {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(ALLOC_SIZE);
        if (this.isPlaying())
            BASS.BASS_ChannelGetData(playerChannel, byteBuffer, BASS.BASS_DATA_FFT1024);
        return byteBuffer;
    }

    @Override
    public boolean isPlaying() {
        return BASS.BASS_ChannelIsActive(playerChannel) == BASS.BASS_ACTIVE_PLAYING;
    }

    @Override
    public void loadSong(final SongPlayerModel songPlayerModel, final LoadCallback loadCallback) {
        if (songPlayerModel == null) {
            if (loadCallback != null)
                loadCallback.onError(new OperationErrorException("Unknown file.", LOAD_RESOURCE_ERROR));
            return;
        }

        this.stop();

        this.playingSong = songPlayerModel;

        if (songPlayerModel.getPath() == null) {
            if (loadCallback != null)
                loadCallback.onError(new OperationErrorException("Song address is empty.", LOAD_RESOURCE_ERROR));
            return;
        }

        if (this.streamAdapter != null) {
            try {
                this.streamAdapter.release();
                this.streamAdapter = null;
            } catch (Exception e) {
                Log.e(TAG, "Resources couldn't be released.");
                if (loadCallback != null)
                    loadCallback.onError(new OperationErrorException("Resources couldn't be released.", OPERATION_ERROR));
                return;
            }
        }
        this.streamAdapter = this.streamAdapterBuilder.build(songPlayerModel.getSource());

        if (this.streamAdapter == null) {
            Log.e(TAG, "Invalid source");
            if (loadCallback != null)
                loadCallback.onError(new OperationErrorException("Invalid source", OPERATION_ERROR));
            return;
        }

        this.streamAdapter.setHandlerCallback(new StreamAdapter.Handler() {
            @Override
            public void onInitialBufferLoaded() {
                BASS.BASS_ChannelRemoveSync(playerChannel, BassPlayer.this.endSyncHandler);

                if (!BASS.BASS_StreamFree(playerChannel))
                    BASS.BASS_MusicFree(playerChannel);

                if ((BassPlayer.this.playerChannel = BASS.BASS_StreamCreateFileUser(BASS.STREAMFILE_NOBUFFER, 0, new BufferHandler(), streamAdapter)) == 0
                        && (BassPlayer.this.playerChannel = BASS.BASS_MusicLoad(streamAdapter.getCachePath(), 0, 0, BASS.BASS_MUSIC_RAMP, 1)) == 0) {
                    if (loadCallback != null)
                        loadCallback.onError(new OperationErrorException("Song couldn't be loaded in memory, error: " + BASS.BASS_ErrorGetCode(), LOAD_RESOURCE_ERROR));
                }

                if (onIPlayerCallback != null)
                    onIPlayerCallback.onPrepared();
                if (equalizer != null)
                    equalizer.attachPlayer(BassPlayer.this);

                BassPlayer.this.endSyncHandler = BASS.BASS_ChannelSetSync(BassPlayer.this.playerChannel, BASS.BASS_SYNC_END, 0, new BASS.SYNCPROC() {
                    @Override
                    public void SYNCPROC(int i, int i1, int i2, Object o) {
                        if (onIPlayerCallback != null)
                            onIPlayerCallback.onSongCompleted(BassPlayer.this.playingSong);
                    }
                }, 0);

                if (loadCallback != null)
                    loadCallback.onLoadComplete();
            }

            @Override
            public void onLoadComplete() {
                //Unused
            }

            @Override
            public void onError(Throwable throwable) {
                if (loadCallback != null)
                    loadCallback.onError(throwable);
            }

            @Override
            public void onStart() {
                if (loadCallback != null)
                    loadCallback.onStart();
            }
        });

        this.streamAdapter.initialize(songPlayerModel.getPath(), songPlayerModel.getAccount());
    }

    @Deprecated
    @Override
    @Nullable
    public IBasicMediaPlayer getBasicMediaPlayer() {
        return null;
    }

    @Override
    public int getSessionId() {
        return this.playerChannel;
    }

    @Override
    public void attachEqualizer(IEqualizer equalizer) {
        this.equalizer = equalizer;
        equalizer.attachPlayer(this);
    }

    @Override
    public void setOnIPlayerCallback(final OnIPlayerCallback onIPlayerCallback) {
        this.onIPlayerCallback = onIPlayerCallback;
    }

    @Override
    public void release() {
        BASS.BASS_Free();
    }

    @Override
    public boolean isSongLoading() {
        return this.streamAdapter != null && this.streamAdapter.isBufferLoading();
    }

    private class BufferHandler implements BASS.BASS_FILEPROCS {

        @Override
        public void FILECLOSEPROC(Object adapter) {
            StreamAdapter streamAdapter = (StreamAdapter) adapter;
            try {
                streamAdapter.release();
            } catch (Exception e) {
                Log.e(TAG, "Error when closing stream: " + e.getLocalizedMessage());
            }
        }

        @Override
        public long FILELENPROC(Object adapter) {
            StreamAdapter streamAdapter = (StreamAdapter) adapter;

            try {
                return streamAdapter.getStreamLength();
            } catch (IOException e) {
                Log.e(TAG, "Error when getting available data in stream: " + e.getLocalizedMessage());
            }
            return 0;
        }

        @Override
        public int FILEREADPROC(ByteBuffer byteBuffer, int length, Object adapter) {
            StreamAdapter streamAdapter = (StreamAdapter) adapter;

            byte[] buffer = new byte[length];
            byteBuffer.clear();
            int readByte = 0;
            try {
                readByte = streamAdapter.read(buffer, 0, length);
                byteBuffer.put(buffer);
            } catch (IOException e) {
                Log.e(TAG, "Error when reading the stream: " + e.getLocalizedMessage());
            }
            return readByte;
        }

        @Override
        public boolean FILESEEKPROC(long offset, Object adapter) {
            StreamAdapter streamAdapter = (StreamAdapter) adapter;

            try {
                streamAdapter.seek(offset);
            } catch (IOException e) {
                Log.e(TAG, "Error when seeking the stream: " + e.getLocalizedMessage());
                return false;
            }

            return true;
        }
    }
}

Any idea what could be wrong?

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: tgkill
« Reply #7 on: 6 Jul '18 - 13:19 »
That looks like BASS was calling some Java method, so possibly your BASS_FILEPROCS functions or Android media codec stuff. Can you try logging the entry and exit of your BASS_FILEPROCS functions to confirm if they're being called? Also check if the crash still happens when you disable the Android media codecs, like this:

Code: [Select]
BASS.BASS_SetConfig(BASS.BASS_CONFIG_AM_DISABLE, 1);

dieppa

  • Posts: 33
Re: tgkill
« Reply #8 on: 11 Jul '18 - 15:05 »
Hi Ian,

I have disabled Android codecs. The application is already more than 48 ours live, over 100k installations and I have got no tgkill crash so far. Seems to work.

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: tgkill
« Reply #9 on: 11 Jul '18 - 17:28 »
OK. That sounds like some Android media codec had a problem with some file. Where is your app getting the file data that it is playing with BASS_StreamCreateFileUser? Would it be possible to add logging of that to find out which file the problem is happening with, after re-enabling the codecs?

dieppa

  • Posts: 33
Re: tgkill
« Reply #10 on: 20 Jul '18 - 10:04 »
Hi Ian,

Disabling Android Codex stops tgkill crashes, but, how does this affect the compatibility with certain formats? Yesterday contacted us a user telling that since last update (where Android codecs were disabled) he can't play mp4 anymore. Has it something to do with?

I can't tell you what file is causing the crash, because the crash was detected in production. None of our testers is capable of reproducing the error. I am not sure if I can log the error in order to know what files are throwing the exception in production, the app just crash, kernel kill. Anyway, if I log it, I will have to ask users to provide anonymous data, not many of them allow that.

Enabling Android codecs will improve any format compatibility? I have tested several format after disabling, every single one were played, just like before.

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: tgkill
« Reply #11 on: 20 Jul '18 - 14:38 »
Yes, if you disable the Android media codecs, that will disable MP4/AAC support unless you use the BASS_AAC add-on.

If you do ever find a file that triggers the problem, please upload it here:

   ftp.un4seen.com/incoming/