At the moment, a couple of things go wrong concerning the PlaylistContainer:
- If
PlaylistContainer ^Session::PlaylistContainer::get() is called when the Session has not logged in yet, an AccesViolationException occurs in the constructor of PlaylistContainer, since the supplied pointer (gotten through sp_session_playlistcontainer) is not valid;
- If the
Session is logged out, and then back in, the PlaylistContainer remains empty, and the count always gives -1. This is because the PlaylistContainer apparently is scoped within a Session login 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 a PlaylistContainer with 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?
At the moment, a couple of things go wrong concerning the
PlaylistContainer: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;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
PlaylistContainerto the login/logout process of theSession.A quick fix is nulling the
_pcpointer inSessionon logout, but this has two disadvantages:PlaylistContainers that were instantiated earlier on are still references somewhere and not GC-ed: they still receive some events from libspotify;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
PlaylistContainerjust once, but re-linking it to libspotify onSessionlogin/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
PlaylistContainerwhen not logged in. I think, with the approach described above, the best option is to be able to retrieve it and throw anExceptionif something is done which requires theSessionto be logged in.Your ideas?