-
Notifications
You must be signed in to change notification settings - Fork 19
Improve management of PlaylistContainer #53
Description
At the moment, a couple of things go wrong concerning the PlaylistContainer:
- If
PlaylistContainer ^Session::PlaylistContainer::get()is called when theSessionhas not logged in yet, anAccesViolationExceptionoccurs in the constructor ofPlaylistContainer, since the supplied pointer (gotten throughsp_session_playlistcontainer) is not valid; - If the
Sessionis logged out, and then back in, thePlaylistContainerremains empty, and the count always gives -1. This is because thePlaylistContainerapparently is scoped within aSessionlogin timespan (see https://developer.spotify.com/docs/libspotify/12.1.51/group__session.html#ga319767f0b795f1c46a08390b587c5671)
All in all, we need to relate the creation of the PlaylistContainer to the login/logout process of the Session.
A quick fix is nulling the _pc pointer in Session on logout, but this has two disadvantages:
- The
PlaylistContainers that were instantiated earlier on are still references somewhere and not GC-ed: they still receive some events from libspotify; - The client may have references to the 'first'
PlaylistContainer. With this fix, this reference silently becomes useless (since it then points to aPlaylistContainerwith count -1).
I think the best option is creating the PlaylistContainer just once, but re-linking it to libspotify on Session login/logout, using the appropriate libspotify methods (sp_session_playlistcontainer, sp_playlistcontainer_add_ref, sp_playlistcontainer_add_callbacks, sp_playlistcontainer_remove_callbacks, sp_playlistcontainer_release).
Also, we need to manage the PlaylistContainer when not logged in. I think, with the approach described above, the best option is to be able to retrieve it and throw an Exception if something is done which requires the Session to be logged in.
Your ideas?