Skip to content

Commit

Permalink
Fix crash when loading project with missing peak controller effect (#…
Browse files Browse the repository at this point in the history
…4391)

* Fix crash when loading project with missing peak controller effect

* Don't load/save dummy controller connections
  • Loading branch information
PhysSong authored Jun 13, 2018
1 parent 2f19fa1 commit 407973a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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

0 comments on commit 407973a

Please sign in to comment.