Replace every use of the foreach macro with a C++11 range-based for loop
This prevents a race condition with Qt5. A foreach loop makes a copy of its Qt container, increasing the reference count to the container's internal data. Qt5 often asserts isDetached(), which requires the reference count to be <= 1. This assertion fails when the foreach loop increases the reference count at exactly the wrong moment. Using a range-based for loop prevents an unnecessary copy from being made and ensures this race condition isn't triggered.
This commit is contained in:
@@ -83,7 +83,7 @@ bool MidiExport::tryExport( const TrackContainer::TrackList &tracks, int tempo,
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
uint32_t size;
|
||||
|
||||
foreach( Track* track, tracks ) if( track->type() == Track::InstrumentTrack ) nTracks++;
|
||||
for( const Track* track : tracks ) if( track->type() == Track::InstrumentTrack ) nTracks++;
|
||||
|
||||
// midi header
|
||||
MidiFile::MIDIHeader header(nTracks);
|
||||
@@ -91,7 +91,7 @@ bool MidiExport::tryExport( const TrackContainer::TrackList &tracks, int tempo,
|
||||
midiout.writeRawData((char *)buffer, size);
|
||||
|
||||
// midi tracks
|
||||
foreach( Track* track, tracks )
|
||||
for( Track* track : tracks )
|
||||
{
|
||||
DataFile dataFile( DataFile::SongProject );
|
||||
MidiFile::MIDITrack<BUFFER_SIZE> mtrack;
|
||||
|
||||
@@ -262,7 +262,7 @@ void ZynAddSubFxInstrument::loadSettings( const QDomElement & _this )
|
||||
m_pluginMutex.unlock();
|
||||
|
||||
m_modifiedControllers.clear();
|
||||
foreach( const QString & c, _this.attribute( "modifiedcontrollers" ).split( ',' ) )
|
||||
for( const QString & c : _this.attribute( "modifiedcontrollers" ).split( ',' ) )
|
||||
{
|
||||
if( !c.isEmpty() )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user