Safely sort view layers

Changing view order of only some layers can cause overwriting of the
original layer if not pre-staged

Fixes https://gitlab.com/kicad/code/kicad/issues/10283

(cherry picked from commit 3e6bf7814b)
This commit is contained in:
Seth Hillbrand 2022-01-06 14:40:02 -08:00
parent fd9d923bb7
commit ac9693bb8d
1 changed files with 5 additions and 11 deletions

View File

@ -679,19 +679,13 @@ void VIEW::ReorderLayerData( std::unordered_map<int, int> aReorderMap )
std::vector<VIEW_LAYER> new_map;
new_map.reserve( m_layers.size() );
for( int ii = 0; ii < VIEW_MAX_LAYERS; ++ii )
new_map.emplace_back();
for( const VIEW_LAYER& layer : m_layers )
new_map.push_back( layer );
for( auto& pair : aReorderMap )
{
int orig_idx = layer.id;
int new_idx = orig_idx;
if( aReorderMap.count( orig_idx ) )
new_idx = aReorderMap.at( orig_idx );
new_map[new_idx] = layer;
new_map[new_idx].id = new_idx;
new_map[pair.second] = m_layers[pair.first];
new_map[pair.second].id = pair.second;
}
m_layers = new_map;