Author Topic: Intermittent Android crash when calling BASS_StreamFree  (Read 97 times)

ben.lacey

  • Posts: 2
In our Android app we're seeing crashes of various sorts (SIGSEGV, SIGBUS, SIGILL) when our app is streaming one stream, then we attempt to play another - I've narrowed it down to when we call BASS_StreamFree(handle) on the previous stream handle.  It also occurs if we use BASS_ChannelStop(handle) when the BASS_STREAM_AUTOFREE option is in use, so it must be caused by something in the freeing of resources.

The streams in question are MP3 radio streams from the BBC, while AAC streams from our content service have been working totally fine with our player these particular streams seem to cause the problem.  It's not totally consistent, and annoyingly I haven't been able to reproduce this in our cut-down test app, but it'll happen once every three or four streams.

Do you have some sort of debug version of the Android libraries that might help us pinpoint what's going wrong when freeing these streams?

Thanks,
Ben.

Ian @ un4seen

  • Administrator
  • Posts: 21329
Please post the crash info (including call stack) from the Logcat window. Also, confirm that you are using the latest BASS version (from the Android thread), and whether you are using the standard or "mp3-free" version? If it's the the "mp3-free" version, please try the standard version and see if the crash still happens then.

ben.lacey

  • Posts: 2
Sorry for the false alarm!  After digging a little further and clutching at a few more straws, I think I've found the reason for this - in Xamarin/C#, using a direct reference to a DOWNLOADPROC delegate method, rather than storing a class-level field referencing it, seems to cause the crash.

So instead of:
Code: [Select]
var stream = Bass.BASS_StreamCreateURL(track.StreamURL, 0, flags, OnDownloadProc, IntPtr.Zero);

private void OnDownloadProc(IntPtr buffer, int length, IntPtr user) { ... }

Code: [Select]
_downloadProc = OnDownloadProc;
var stream = Bass.BASS_StreamCreateURL(track.StreamURL, 0, flags, _downloadProc, IntPtr.Zero);

private void OnDownloadProc(IntPtr buffer, int length, IntPtr user) { ... }

The original crash had this sort of stack, for anyone searching for the same thing:

Code: [Select]
11-08 08:50:51.380: A/libc(10319): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x73 in tid 10936 (Thread-32)
11-08 08:50:51.380: A/libc(10319): [ 11-08 08:50:51.381   272:  272 W/         ]
11-08 08:50:51.380: A/libc(10319): debuggerd: handling request: pid=10319 uid=10276 gid=10276 tid=10936
11-08 08:50:51.415: A/DEBUG(10969): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-08 08:50:51.415: A/DEBUG(10969): Build fingerprint: 'google/shamu/shamu:7.1.1/N6F27M/4299435:user/release-keys'
11-08 08:50:51.415: A/DEBUG(10969): Revision: '0'
11-08 08:50:51.415: A/DEBUG(10969): ABI: 'arm'
11-08 08:50:51.415: A/DEBUG(10969): pid: 10319, tid: 10936, name: Thread-32  >>> com.***.dev <<<
11-08 08:50:51.415: A/DEBUG(10969): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x73
11-08 08:50:51.415: A/DEBUG(10969):     r0 00000000  r1 00000000  r2 00000000  r3 92755d70
11-08 08:50:51.415: A/DEBUG(10969):     r4 07e8c8c0  r5 90173740  r6 8857f920  r7 00000078
11-08 08:50:51.415: A/DEBUG(10969):     r8 8887dc1c  r9 8887dbc8  sl 9014e885  fp 00000073
11-08 08:50:51.415: A/DEBUG(10969):     ip 90168e9c  sp 8857f900  lr 9014e8c1  pc 92755d8c  cpsr 20070010
11-08 08:50:51.420: A/DEBUG(10969): backtrace:
11-08 08:50:51.420: A/DEBUG(10969):     #00 pc 00007d8c  <anonymous:9274e000>
11-08 08:50:51.420: A/DEBUG(10969):     #01 pc 0001c8bf  /data/app/com.***.dev-1/lib/arm/libbass.so
11-08 08:50:51.420: A/DEBUG(10969):     #02 pc 00047093  /system/lib/libc.so (_ZL15__pthread_startPv+22)
11-08 08:50:51.420: A/DEBUG(10969):     #03 pc 00019bdd  /system/lib/libc.so (__start_thread+6)

Thanks for the offer of help, and sorry for wasting a bit of your time! :)

Ian @ un4seen

  • Administrator
  • Posts: 21329
Yes, if you're using .Net, you will need to keep references to callback delegates to prevent them getting garbage collected. More information on that can be found in the "Callbacks and Delegates" section of the "Interoperating with Unmanaged Code" page in the BASS.Net documentation.