mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 09:04:33 +02:00
Store a strong reference to a playlist pointer so it will not be destroyed before the postCommitHook finishes
This commit is contained in:
@@ -108,27 +108,21 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
||||
tLog() << "Postcommitting this playlist:" << playlistguid() << source().isNull();
|
||||
|
||||
// private, but we are a friend. will recall itself in its own thread:
|
||||
DynamicPlaylist* rawPl = 0;
|
||||
dynplaylist_ptr playlist = source()->dbCollection()->autoPlaylist( playlistguid() );
|
||||
if ( playlist.isNull() )
|
||||
{
|
||||
playlist = source()->dbCollection()->station( playlistguid() );
|
||||
}
|
||||
|
||||
if ( !playlist.isNull() )
|
||||
{
|
||||
rawPl = playlist.data();
|
||||
}
|
||||
else
|
||||
if ( playlist.isNull() && !m_playlist.isNull() )
|
||||
{
|
||||
// if it's neither an auto or station, it must not be auto-loaded, so we MUST have been told about it directly
|
||||
rawPl = m_playlist;
|
||||
playlist = m_playlist;
|
||||
}
|
||||
|
||||
if ( !rawPl )
|
||||
if ( playlist.isNull() )
|
||||
{
|
||||
tLog() << "Got null playlist with guid:" << playlistguid() << "from source and collection:" << source()->friendlyName() << source()->dbCollection()->name() << "and mode is static?:" << (m_mode == Static);
|
||||
// Q_ASSERT( false );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,13 +133,13 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
||||
controlMap << v.toMap();
|
||||
|
||||
if ( m_mode == OnDemand )
|
||||
rawPl->setRevision( newrev(),
|
||||
playlist->setRevision( newrev(),
|
||||
true, // this *is* the newest revision so far
|
||||
m_type,
|
||||
controlMap,
|
||||
m_applied );
|
||||
else
|
||||
rawPl->setRevision( newrev(),
|
||||
playlist->setRevision( newrev(),
|
||||
orderedentriesguids,
|
||||
m_previous_rev_orderedguids,
|
||||
m_type,
|
||||
@@ -157,13 +151,13 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
|
||||
else
|
||||
{
|
||||
if ( m_mode == OnDemand )
|
||||
rawPl->setRevision( newrev(),
|
||||
playlist->setRevision( newrev(),
|
||||
true, // this *is* the newest revision so far
|
||||
m_type,
|
||||
m_controls,
|
||||
m_applied );
|
||||
else
|
||||
rawPl->setRevision( newrev(),
|
||||
playlist->setRevision( newrev(),
|
||||
orderedentriesguids,
|
||||
m_previous_rev_orderedguids,
|
||||
m_type,
|
||||
@@ -269,9 +263,9 @@ DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib )
|
||||
}
|
||||
|
||||
void
|
||||
DatabaseCommand_SetDynamicPlaylistRevision::setPlaylist( DynamicPlaylist* pl )
|
||||
DatabaseCommand_SetDynamicPlaylistRevision::setPlaylist( QWeakPointer<DynamicPlaylist> pl )
|
||||
{
|
||||
m_playlist = pl;
|
||||
m_playlist = pl.toStrongRef();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -76,8 +76,7 @@ public:
|
||||
void setType( const QString& type ) { m_type = type; }
|
||||
void setMode( int mode ) { m_mode = (GeneratorMode)mode; }
|
||||
|
||||
// TODO: Pass wptr here, so we can get a strong reference again
|
||||
void setPlaylist( DynamicPlaylist* pl ); // raw pointer b/c we don't have the shared pointer from inside the shared pointer
|
||||
void setPlaylist( QWeakPointer<DynamicPlaylist> pl ); // raw pointer b/c we don't have the shared pointer from inside the shared pointer
|
||||
|
||||
private:
|
||||
QString m_type;
|
||||
@@ -85,8 +84,7 @@ private:
|
||||
QList< dyncontrol_ptr > m_controls;
|
||||
QList< QVariant > m_controlsV;
|
||||
|
||||
// ARG i hate sharedpointers sometimes
|
||||
DynamicPlaylist* m_playlist; // Only used if setting revision of a non-autoloaded playlist, as those aren't able to be looked up by guid
|
||||
QSharedPointer<DynamicPlaylist> m_playlist; // Only used if setting revision of a non-autoloaded playlist, as those aren't able to be looked up by guid
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -242,7 +242,7 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
||||
Static,
|
||||
controls );
|
||||
if ( !d->autoLoad )
|
||||
cmd->setPlaylist( this );
|
||||
cmd->setPlaylist( d->weakSelf );
|
||||
|
||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||
}
|
||||
@@ -278,7 +278,7 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
||||
OnDemand,
|
||||
controls );
|
||||
if ( !d->autoLoad )
|
||||
cmd->setPlaylist( this );
|
||||
cmd->setPlaylist( d->weakSelf );
|
||||
|
||||
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||
}
|
||||
|
Reference in New Issue
Block a user