0

I'm getting a segmentation fault using if I try to call sp_session_logout after playing a song. I can't really say much about the segfault, as I don't have the symbols,

With the following code the segfault occurs every time after logout is called https://gist.github.com/ivankelly/5564318

#0  0x00007ffff7ac5746 in ?? () from /home/ivan/Apps/lib/libspotify.so.12
#1  0x00007ffff7a38289 in ?? () from /home/ivan/Apps/lib/libspotify.so.12
#2  0x00007ffff7a38535 in ?? () from /home/ivan/Apps/lib/libspotify.so.12
#3  0x00007ffff7a39b5a in ?? () from /home/ivan/Apps/lib/libspotify.so.12
#4  0x00007ffff7a39c86 in ?? () from /home/ivan/Apps/lib/libspotify.so.12
#5  0x00007ffff79fbc8b in ?? () from /home/ivan/Apps/lib/libspotify.so.12
#6  0x00007ffff7ad05b3 in sp_session_process_events () from /home/ivan/Apps/lib/libspotify.so.12
#7  0x0000000000401986 in main (argc=3, argv=0x7fffffffe6f8) at /home/ivan/src/spotify_test/test_spotify.c:137

This is on debian sid with libspotify 12.1.51 (x86_64).

Ivan Kelly
  • 204
  • 1
  • 3

1 Answers1

3

You're calling the logout inside a libspotify callback, specifically a music delivery related one. Music delivery callbacks happen on their own thread, and libspotify isn't thread safe like this — you must call all APIs on the "main" thread (specifically, the thread on which you called sp_session_create on).

Your crash can most likely be fixed by either not calling logout when your test_spotify_end_of_track callback is fired, or by marshalling over to the main thread when it is and calling logout there.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • Same thing happens when I put the logout in the main thread (see updated gist). Also, if session release is called, skipping the logout, i also get a segfault. – Ivan Kelly May 13 '13 at 07:19
  • Whenever I call sp_session_process_events after sp_session_logout I also get a crash. – Matthew Mitchell Sep 27 '13 at 20:23