This happens after a layer that is not the "last" (the layer with largest key in the hashmap) is deleted. Although the layer does get deleted, the remaining mappings in the hashmap are not rearranged so that the "hole" in the key sequence is closed.
mpWindow::AddLayer() will then replace the last layer with the layer passed as argument, since the "key" returned by m_layers.size() is already mapped to a layer.
Example: a plot initially with four layers
Key 0 -> layer A
Key 1 -> layer B
Key 2 -> layer C
Key 3 -> layer D
After removing layer C and the mappings are:
Key 0 -> layer A
Key 1 -> layer B
Key 3 -> layer D
If a new layer is added, it will overwrite the last mapping since m_layers.size() will return 3.
Logged In: YES
user_id=1669489
Originator: NO
Fixed in Subversion development code. m_layers has become a std::deque of mpLayer pointers in the meanwhile.