Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when loading project with missing peak controller effect #4391

Merged
merged 2 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, co
element.setAttribute( name, m_value );
}

if( m_controllerConnection )
if( m_controllerConnection && m_controllerConnection->getController()->type()
!= Controller::DummyController )
{
QDomElement controllerElement;

Expand Down
7 changes: 6 additions & 1 deletion src/core/ControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ void ControllerConnection::finalizeConnections()
c->setController( Engine::getSong()->
controllers().at( c->m_controllerId ) );
}
else if (c->getController()->type() == Controller::DummyController)
{
delete c;
--i;
}
}
}

Expand Down Expand Up @@ -199,7 +204,7 @@ void ControllerConnection::loadSettings( const QDomElement & _this )
}
else
{
if( _this.attribute( "id" ).toInt() >= 0 )
if( _this.attribute( "id", "-1" ).toInt() >= 0 )
{
m_controllerId = _this.attribute( "id" ).toInt();
}
Expand Down
15 changes: 12 additions & 3 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,11 @@ void Song::loadProject( const QString & fileName )
// now that everything is loaded
ControllerConnection::finalizeConnections();

// Remove dummy controllers that was added for correct connections
m_controllers.erase(std::remove_if(m_controllers.begin(), m_controllers.end(),
[](Controller* c){return c->type() == Controller::DummyController;}),
m_controllers.end());

// resolve all IDs so that autoModels are automated
AutomationPattern::resolveAllIDs();

Expand Down Expand Up @@ -1289,9 +1294,13 @@ void Song::restoreControllerStates( const QDomElement & element )
while( !node.isNull() && !isCancelled() )
{
Controller * c = Controller::create( node.toElement(), this );
Q_ASSERT( c != NULL );

addController( c );
if (c) {addController(c);}
else
{
// Fix indices to ensure correct connections
m_controllers.append(Controller::create(
Controller::DummyController, this));
}

node = node.nextSibling();
}
Expand Down